Ogr2ogr Or arc for csv to shapefile?

Can ogr2ogr or arcpy do a direct conversion from csv to shapefile? I am trying to automate some processes with a small script and was hoping that I could do this with ogr2ogr or arcpy, for which I am new.

Any input would be appreciated.

+4
source share
2 answers

This can be done with ogr2ogr.

Assuming you have a csv file containing the coordinates, for example (should be separated by a comma):

coord.csv

x,y,z
48.66080825,10.28323850,0
48.66074700,10.28292000,0
48.66075045,10.28249425,0
48.66075395,10.28249175,0
48.66077113,10.28233356,0
48.66080136,10.28213118,0
48.66079620,10.28196900,0

Then you need to create a sample file (name it according to your csv) in the same directory:

coord.vrt

<OGRVRTDataSource>
  <OGRVRTLayer name="output">
    <SrcDataSource relativeToVRT="1">.</SrcDataSource>
    <SrcLayer>coord</SrcLayer>
    <GeometryType>wkbPoint</GeometryType>
    <LayerSRS>WGS84</LayerSRS>
    <GeometryField encoding="PointFromColumns" x="x" y="y"/>
  </OGRVRTLayer>
</OGRVRTDataSource>

Then run:

ogr2ogr -f "ESRI Shapefile" . coord.csv && ogr2ogr -f "ESRI Shapefile" . coord.vrt

"output.shp" , .

,

muxav

+11

CSV- , Python arcpy site-package:


.

import arcpy
from arcpy import env

# Set environment settings
env.workspace = "C:/data"
ws = env.workspace

# Set the local variables
in_Table = "your_table.csv"
x_coords = "POINT_X"
y_coords = "POINT_Y"
z_coords = "POINT_Z"
out_Layer = "your_layer"

# Set the spatial reference--this is simply a path to a .prj file
spRef = r"Coordinate Systems\Projected Coordinate Systems\Utm\Nad 1983\NAD 1983 UTM Zone 11N.prj"

# Make the XY event layer...
arcpy.MakeXYEventLayer_management(in_Table, x_coords, y_coords, out_Layer, spRef, z_coords)

# Now convert to a feature class
arcpy.FeatureClassToFeatureClass_conversion (out_layer, ws, "out.shp")
+1

Source: https://habr.com/ru/post/1532415/


All Articles