New answers tagged

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":{"...


0

If you are looking for pure python with gdal on your cmd you need to do follow steps: Step 1: Install pure python from python.org Feel free to download the latest 2.7x version of python (rather than the 3.x python version). Install python with the default options and directories. Step 2: Next Install the GDAL Binaries Head over to Tamas Szekeres’ Windows ...


1

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 ...


0

You need to have "write" access to the data source. In this case the data source is a web page resulting from a query. One solution is to create a copy of the data source in the computer's memory, and, then add to that memory: #create an output datasource in memory mem_driver=ogr.GetDriverByName('MEMORY') source = mem_driver....


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&...


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')


0

I'm not an expert regarding python + GDAL/OGR, but looking into something similar I found a possible answer to your question. import ogr, osr import fileinput from datetime import datetime srs = osr.SpatialReference() srs.ImportFromEPSG(4326) driver = ogr.GetDriverByName("GPX") out = driver.CreateDataSource('/tmp/test.gpx') # layer creation: if you use '...


0

In ogr2ogr you have dataset creation options, and layer creation options. According to http://www.gdal.org/drv_gpx.html, FORCE_GPX_TRACK=YES is a LAYER creation option. So you have to add -lco "FORCE_GPX_TRACK=YES" to get the tracks instead of routes. This works for the command line version just the same. Make sure the data is in EPSG:4326. The above ...


0

In order to get geographic coordinates from a Shapefile with projected spatial reference, the geometries need to be reprojected when working with OGR. I tried to avoid this at first, because I'm working in a custom spatial reference system and I'm not sure about the reprojection parameters. When I look at the reprojected data in a GIS, they seem to be ...


0

For you, what is the difference between geographic coordinates and projected coordinates ? From ESRI GeoNet: Projected Coordinate System vs. Geographic Coordinate System: A Geographic Coordinate Systems is defined by a 3-D surface and is measured in latitude and longitude. A Projected Coordinate systems refers to data that is defined by a flat 2-D surface ...


0

I have solved it - the map 'screwing up' was, of course, the land masses going beyond +/- 180 degrees. The solution is therefore to clip the land mass data against the gore shape before rendering, which prevents this from happening (and is a little neater than the mask anyway). I never found out why the projection wasn't updating after I had edited the WKT, ...


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) ...


1

WKT is only a text markup language for representing vector geometry, therefore you cannot convert 3D WKT to 2D (= text to text), you need to change the geometry The problem with ogr is that it seems that all the geometries are 3D by defaut 1) Creation of a 2D point with ogr point = ogr.Geometry(ogr.wkbPoint) # 2D point point.AddPoint(1198054.34, 648493.09)...



Top 50 recent answers are included