Spatialise a CSV file with Easting & Northing attributes
If you wish to import data from a CSV file, that has Easting and Northing attributes, into Data Share or any other PostgreSQL database this can be done using the Spatial Data Transformation Task using the OGR Virtual Format driver.
This allows you to create the geometry as part of the import.
The following steps are based on the example test.csv file below. You will notice that the first two columns are the easting and northing fields.
easting,northing,name 450001,250001,"First point" 450101,250101,"Second point" 450201,250201,"Third point"
- Create the XML Control file for the OGR VRT driver
- Create the Spatial Data Transformation Task to Import the CSV file.
Step 1 - Creating the XML Control file
You will first need to create the XML Control file for the OGR VRT driver.
- Create a file called test.vrt with the following content.
Typically you would give the control file the same name as the .csv file (discounting the extension).
<OGRVRTDataSource> <OGRVRTLayer name="test"> <SrcDataSource>C:\test\test.csv</SrcDataSource> <GeometryType>wkbPoint</GeometryType> <LayerSRS>EPSG:27700</LayerSRS> <GeometryField encoding="PointFromColumns" x="easting" y="northing"/> </OGRVRTLayer> </OGRVRTDataSource>
OGRVRTLayer
Enter a name for the Layer. This MUST have the same name as the csv file (discounting the extension).
SrcDataSource
Enter the path to your CSV file.
GeometryType
As we are importing Point data this will be wkbPoint.
LayerSRS
This needs to be left as EPSG:27700 for British National Grid.
GeometryField
Make sure that the GeometryField encoding x & y entries match the names of your easting and northing columns respectively.
Step 2 - Creating the Spatial Data Transformation Taks
Now in Studio select to create a Spatial Data Transformation Task.
Task Name
Enter a name for the task.
Source Data
Select Comma-Delimited Text File as the list.
If Comma-delimited Text File does not exist in the list of "Source Data" types then you will need to edit the ConTypes.xml file, which you will find in the ...Astun\iShare\n.n\Studio\config folder. If you open ConTypes.xml with a text editor you will see options for DBConTypes (servers, such as PostgreSQL and Oracle) and FileConTypes (file formats such as shapefile or mapinfo tab). Create a new FileConType entry after the last closing </FileConType> tag (but before the closing </ConnectionTypes> tag as follows:
<FileConType> <Name>Comma-Delimited Text File</Name> <FormatName>CSV</FormatName> <Direction>Both</Direction> <FileFilter>Comma-Delimited Text files (*.csv)|*.csv</FileFilter> </FileConType>
Filename
Enter the path to the .vrt file for the csv file you wish to Import.
Output
Select the PostgreSQL database where you wish to store this data.
Table
Enter the table name where you wish to store the data in the database.
Now you just need to click on the Run button to run the task to import the data.