New answers tagged

2

The answer from user30184 was correct. Adding target.SetAxisMappingStrategy(osr.OAMS_TRADITIONAL_GIS_ORDER) after importing the SR from an EPSG code gave me the desired output! Here is the example code I posted before, showing how it is used. from osgeo import ogr,osr source = osr.SpatialReference() source.ImportFromEPSG(26913) target = osr.SpatialReference()...


1

I fear it is at least quite difficult task with shapefiles. As documented in https://gdal.org/drivers/vector/gpx.html it is possible to combine several layers from a datasource into gpx. The example is using gpx as input and outputformat ogr2ogr -f GPX output.gpx input.gpx waypoints routes tracks but as well the source could be some other format ogr2ogr -f ...


0

You have to use DXF_FEATURE_LIMIT_PER_BLOCK with the --config switch. ogr2ogr --config DXF_FEATURE_LIMIT_PER_BLOCK -1


2

Mount your directory to the docker container ...Of course you need to do that. Otherwise the docker container won't contain any contents and the file myShapefile.shp is just not present and the command fails. Use the -v flag to mount a [local directory]:[container directory]. Full command; docker run --rm -v /home/user/data:/data osgeo/gdal:ubuntu-full-3.4.1 ...


2

Here's a potential solution following suggestions from jbalk's and user30184's comments. It uses OGR's SetMeasured function to drop the M-values and relies on WKB (instead of WKT) to do the actual conversion between OGR and Shapely. def from_ogr_to_shapely(ogr_geom): # Creating a copy of the input OGR geometry. This is done in order to # ensure that ...


0

@Mike T's post tells you about some of the caveats of using OGR, but it doesn't actually answer your main question: how can you generate a copy of an OGR geometry? I'm not sure if this is the best way to do so, but here's a simple and generic solution: gPrevious = ogr.CreateGeometryFromWkb(gCurrent.ExportToIsoWkb()) Now you don't have two references that ...


1

The reason why you're getting a 3D object is because you are using the AddPoint method instead of the AddPoint_2D method. As seen in the OSGEO/OGR/GDAL documentation, the AddPoint method expects all three coordinates as arguments: x, y and z. If you only pass it two arguments, it will assume z=0. If, instead, you really want to work with 2D geometries, just ...


0

As pointed out by @mikewatt, it seems like I cannot add a point geometry directly. The best I can do is use the GetPoint or GetPoint_2D methods and pass the Point geometry's coordinates to the LineString geometry, as shown below: from osgeo import ogr coords_p1 = [1214242.4174581182, 617041.9717021306] coords_p2 = [1234593.1427447330, 629529.9167643716] ...


3

EPSG:4326 is officially using axis order latitude-longitude but PostGIS and many others are using longitude-latitude order that has been a tradition in GIS. Turn the coordinates into "POINT (45.0589613134642 16.0317217831498) >>> point = ogr.CreateGeometryFromWkt("POINT (45.0589613134642 16.0317217831498)") >>> point....


Top 50 recent answers are included