Hot answers tagged

2

I didn't knew geopandas, it is very easy to add a field, a great library indeed. You just need to read your file add it and save. dataSrc = gpd.read_file('my_shp.shp') dataSrc['new_field'] = 1 dataSrc.to_file('newfile.shp') Selecting is also straightforward: dataSrc = gpd.read_file('my_shp.shp') dataSrc[dataSrc['id']<4].to_file('new_shape.shp')


2

GDAL has no problem with GeoJSON http://geojson.org/geojson-spec.html. The following GeoJSON encodes one multilinestring: { "type": "FeatureCollection", "features": [ { "type": "Feature", "geometry": {"type":"MultiLineString","coordinates":[[[11.20558631,46.48251782],[11.2058444,46.48280049]],[[11.20578705,46.48252192],[11.20596731,46.48275133]]],"crs":{"...


2

OGR method, courtesy of this page: from osgeo import ogr conx = ogr.Open('PG:dbname=my_db user=postgres password=12345678') sql = 'SELECT * FROM table_name LIMIT 10;' for row in conx.ExecuteSQL(sql): print row.GetField(0) #gets first column, usually the id Another way: Adapted from here. Doesn't use ogr but it does let you access the data a bit more ...


1

Thanks to user30184! You helped me solve it. The SrcLayer must specify the same name as the CSV file. Here is the correct, working VRT file. The change is on line 4: <OGRVRTDataSource> <OGRVRTLayer name="example"> <SrcDataSource>D:\Temp\example_short.csv</SrcDataSource> <SrcLayer>example_short</SrcLayer&...


1

1) I just don't know how to convert .geojson file to .shp. This is a one of the bases of ogr Python. If you have a geometry, it is very easy to convert it to a shapefile # geojson is GeoJson Polygon from osgeo import ogr output = "geojson.shp" driver = ogr.GetDriverByName('ESRI Shapefile') if os.path.exists(output): driver.DeleteDataSource(output) ...



Only top voted, non community-wiki answers of a minimum length are eligible