Tag Info

1

This converts the input to a numpy array, iterates over all the elements (pixels), finds the lat/long of the all the pixels whose value is 1, and writes those to a shapefile. It uses GDAL and OGR, as well as Numpy, all via Python. I haven't tested it! And, I'm borrowing heavily from Zachary Bears here: ...

4

Keep it simple, you don't need if f1 is Noneand others (assuming that you know the shapefiles to handle) in a simple personal script. Here is a simple solution with your data (with one polygon in each shapefile) from osgeo import ogr poly1 = ogr.Open('poly1.shp') poly2 = ogr.Open('poly2.shp') layer1 = poly1.GetLayer() layer1.GetFeatureCount() 1 # first ...

0

Just truncate the field names before writing your shapefile using strtrim(). So simple. table <- data.frame(X_Coordinates = runif(10)*1000, Y_Coordinates = runif(10)*1000, StupidLongFieldNameForData = runif(10)) points <- SpatialPointsDataFrame(SpatialPoints(table), data = table) ...

3

When you tell GDAL to use SQLite SQL dialect the most part of the work is done by Spatialite library. Couple of weeks ago another user reported that ST_Collect in Spatialite was pretty slow for any bigger tasks https://groups.google.com/forum/#!topic/spatialite-users/t3QrvA1qQyg. Week after that Alessandro Furieri announced about a code optimization which ...

2

You can use PyQGIS code (I know that you use Ubuntu) at the Python Console of QGIS. To test my sugestion, I used the next code where a QgsExpression object has your class 1 values: layer = iface.activeLayer() expression = QgsExpression( u'"values" >= 30 AND "values" <= 50' ) idx = [ feat.attributes()[0] for feat in layer.getFeatures() if ...

0

i'm not sure about the ogr2ogr command line tools, though i tend to do similar processes using ogr in python - something like: (assuming these are shapefiles) from osgeo import ogr def ogrClip(polys, points, clipppedPoints): # not certain if a separate driver is required for each shapefile? shpdrv = ogr.GetDriverByName('ESRI Shapefile') ...

0

The problem here is that OGR’s ExportToGML doesn’t declare a namespace prefix / uri in the output, which would make the ExecuteResponse XML choke parsers. I've opened a GDAL ticket to address this. In the meantime, as a workaround, you can adjust the output of ExportToGML as described here, i.e.: def _setNamespace(xml, prefix, uri): return ...

2

This gave me endless hours of frustration, and the above answers (even the ones in the comments) didn't work for me either, but I found my own solution that did the trick. It turns out that to do an intersection or a clip between two layers, they must be saved on disk with the same CRS. So even if they look like they overlap in QGIS, it may be doing it's ...

3

I ran your script (slightly modified) at the Python Console of QGIS: from osgeo import ogr vlayer = iface.activeLayer() provider = vlayer.dataProvider() path = provider.dataSourceUri() tmp = path.split("|") path_to_shp_data = tmp[0] driver = ogr.GetDriverByName("ESRI Shapefile") dataSource = driver.Open(path_to_shp_data, 1) layer = ...

2

Bingo. It involved a little witchcraft piping two ogr2ogr instructions together via STDIN/OUT, and you'll need to adapt it to your purposes, but something like this should work: ogr2ogr -f "GeoJSON" /vsistdout/ -dialect sqlite -sql " SELECT fullname, COUNT(*) as ct FROM ROADS_3857 GROUP BY fullname " "C:\xGIS\Vector\ROADS_3857.shp" | ogr2ogr -f "CSV" -where ...

2

This is mostly a SQL question that fits better to stackoverfow. First error in your SQL is that you use "GROUP BY road_name" but you have not selected "road_name". Another error is that aggregate functions like count() can't generally be used in WHERE but it must be placed into HAVING or into a subquery. See ...

2

In addition to @Ali's answer... My guess is the Clone() method calls for a deep copy of the object. Where the other method provides a shallow copy. The differences come as one only copies the memory pointer while the other copies the entirety and stores it in another memory location. Since OGR is a C++ library, you can check out this tutorial on C++ ...

2

From my experience the difference is subtle in that GetGeometryRef() will store a reference to the geometry which will be removed when the underlying feature is destroyed. If you use Clone() when storing the geometry you can access it and its methods even after destroying the feature. To highlight this, suppose you want to open a shapefile, read a feature ...

1

It seems that the ubuntugis repositories don't get updated to new Ubuntu versions. You may find current GDAL ubuntu packages here: https://launchpad.net/ubuntu/+source/gdal https://launchpad.net/ubuntu/vivid/+package/gdal-bin

0

You need to set up your environmental variables for it to be recognised as a command by the command prompt. See: http://gisforthought.com/setting-up-your-gdal-and-ogr-environmental-variables/ Alternatively supply the full path to your GDAL/ogr install. Like: C:\OSGeo4W64\bin\ogrinfo.exe myshapefile.shp Or run the command from the same folder as your ...

5

If pol.shp contains your polygons and pnt.shp - points: Create input.vrt: <OGRVRTDataSource> <OGRVRTLayer name="pol"> <SrcDataSource>pol.shp</SrcDataSource> <SrcLayer>pol</SrcLayer> </OGRVRTLayer> <OGRVRTLayer name="pnt"> <SrcDataSource>pnt.shp</SrcDataSource> ...

1

On windows, you must specify the full path to the ogrinfo executable. On my windows 7 machine it is: C:\Python33\Lib\site-packages\osgeo\ogrinfo

2

It might depend on your operating system which you did not mention. Usually "command > filename" works to print the output into a file instead of the terminal.

1

Adding 'MERGE_ALG=ADD' to the list of options to gdal.RasterizeLayer() did the trick, thanks to kyle. An example: gdal.RasterizeLayer(target_ds, [1], src_layer, options = ['MERGE_ALG=ADD']) This is documented in http://www.gdal.org/gdal__alg_8h.html.

3

Here are the one-liners for you, please check them for field/filenames etc. Add a new field: ogrinfo input.shp -sql "ALTER TABLE input ADD COLUMN field3 integer(5)" Do the math (you will need your SQLite driver to be compiled with SQLite SQL dialect): ogrinfo input.shp -dialect SQLite -sql "UPDATE input SET field3 = field1/field2" I don't see where ...

Top 50 recent answers are included