Questions tagged [ogr]
The OGR Simple Features Library is a C++ open source library (and command line tools) providing access to vector file formats.
1,097
questions
2
votes
1
answer
221
views
OGR create polygon giving four corners from raster pixel position
How do I create a geometry from pixels positions in GeoTiff?
ds = gdal.Open("image.tif")
myarray = np.array(ds.GetRasterBand(1).ReadAsArray())
shape = ogr.Geometry(ogr.wkbLinearRing)
And ...
1
vote
1
answer
164
views
ogrmerge with list of input file names from a text file
How might I feed ogrmerge the list filenames to use as input from a text file?
Obvious things like the below do not work; there's no indication from the doc page that it's supposed to. Still this has ...
1
vote
1
answer
563
views
Can OGR SQL dialect be used with GeoPackage?
I'm using GDAL (3.3.1) Python (3.8.11) bindings to process vector layers and am trying to use OGR SQL dialect to filter the layer, like this:
sql = f"SELECT * from {out_lyr.GetName()} WHERE ...
1
vote
2
answers
711
views
osgeo/ogr function that smooths geometry/vertex like qgis/processing toolbox/smooth
In QGIS, I want smooth a shapefile/vector's vertices.
I can use QGIS/processing_toolbox/smooth.
If I want to programmingly achieve this using osgeo/ogr/gdal, which function should I use?
3
votes
1
answer
2k
views
Opening DGN using Python
I'm trying to open a DGN file with Python.
I've tried with OGR:
driver = ogr.GetDriverByName("DGN")
file = driver.Open("C:\path_to_dgn\example.dgn")
which returns a NoneType ...
0
votes
1
answer
691
views
Creating LineString geometry from Point geometries with Python's OSGEO/OGR library
Is it possible to create a LineString object with Python's osgeo/ogr library starting from multiple Point objects?
For example, I know from the Python GDAL/OGR Cookbook that I can create a ...
1
vote
1
answer
405
views
Creating Python OSGEO/OGR geometry with M-values (not using WKT)
I am trying (and failing) to generate M-value geometries (e.g. POINT M, POINT ZM, LINESTRING M, ...) with Python's osgeo/ogr library.
Here is what I've tried to far:
import ogr
# Use OGR specific ...
2
votes
1
answer
672
views
How do you preserve the ID field when using the osgeo/ogr/gdal VectorTranslate function in Python?
When using the Python osgeo/gdal/ogr library, how can I force the feature ID column (e.g., "OBJECTID" or "FID" columns) to be preserved in the output file?
I thought I would just ...
7
votes
1
answer
266
views
QGIS Stand alone python script terminating problem
I want to write Python standalone QGIS script to layout export and my code is as follows:
import os
from qgis.core import (
QgsVectorLayer,QgsProject, QgsWkbTypes,QgsVectorLayerExporter,...
1
vote
1
answer
823
views
How can I use the Python osgeo/ogr library to export a feature layer to CSV with geometries coded as WKT?
How can I read in a layer's data using the python osgeo/ogr library and then export the whole attribute table and an extra column with the geometries coded as WKT to a CSV format?
I know that this is ...
1
vote
0
answers
311
views
Use relative path in VRT with VSIZIP
I'm trying to load a GPKG file into QGIS by a VRT file. The vector is inside a ZIP. So I'm using the vsizip. I would like to use just relative paths. But when I try to load it, the new layer comes ...
1
vote
1
answer
208
views
Python GDAL/OGR, SetAttributeFilter not working
I'm following the book 'Geoprocessing with python', and I'm just trying to filter countries by their continent with this code:
from osgeo import ogr
import ospybook as pb
fn = os.path.join(data_dir, '...
2
votes
0
answers
809
views
Reproject vector layer with OGR and python
I want to reproject a vector Geopackage from WGS (4326) to UTM (32605) using OGR and python. However, after running the code below the feature geometry and data extent is still in degrees and not in ...
0
votes
1
answer
210
views
GDAL where clause failing
I have written an ogr2ogr script to convert well known text values into reprojected geometry table, however even when excluding values with the value "NULL" (as opposed to no value at all) ...
2
votes
1
answer
976
views
GDAL/OGR convert AutoCAD DWG to shapefile
I'm trying to come up with a Python script to convert CAD files to shapefiles. The Open() calls don't error they just return None. I've tried with and without the 'CAD' driver specified.
GDAL version ...
3
votes
1
answer
712
views
Exporting Oracle table with multiple geometry columns to gpkg by using ogr2ogr
I am using ogr2ogr to export a table in Oracle to GPKG. The table in Oracle has two columns (GEOMETRY_2, GEOMETRY_20) with geometry info.
I am using the following ogr2ogr command to export the table ...
0
votes
1
answer
61
views
Slicing shapefile by negative coordinates
I have a shapefile that contains data for both sides of the Greenwich meridian.
According to ogrinfo, this shapefile has the extents of (-9.298157, 35.265607) - (4.327108, 45.046054). I want to copy ...
0
votes
1
answer
272
views
PyQGIS checking a vector layer is not already loaded in a GIS instance
I want to check if a vector layer (filepath) can be used in the pyqgis algorithm processing module. Before using the processing module, I need to check the layer is not loaded in a Q instance, if it ...
0
votes
1
answer
75
views
Count then remove similar polygon features
Is there a feature, preferably in OGR, that will remove duplicate polygons and add a count of duplicates to the remaining features attribute field?
0
votes
3
answers
152
views
ogr2ogr KML Conversion skips Geometries with Corrupt Data error
I have an ogr2ogr bat file to convert SQL to KML that has worked fine for years. All of a sudden the three most recent geometries aren't appearing in the kml file it produces. The error is "ERROR ...
1
vote
0
answers
140
views
Removing holes from shapefile in OGR call (or adding additional OGR calls)
I have:
and after using this ogr2ogr call:
ogr2ogr -dialect sqlite -sql "select st_union(geometry) from tmpem122" -explodecollections dissolved.shp tmpem122.shp
I get:
The problem is to ...
0
votes
1
answer
303
views
"no such field as `OGR_GEOMETRY'" when changing Multipolygon to Polygon with altering geometry in shapefile
The attempt is to change from multipolygon to polygon (shapefile) using:
ogrinfo tmpem122.shp -sql "alter table tmpem122 alter column OGR_GEOMETRY type geometry(polygon, 4326) using st_geometryn(...
3
votes
2
answers
234
views
Losing CRS definition saving to GeoPackage with PyQGIS
I'm using PyQGIS to run the processing algorithm "qgis:extractbyextent". The algorithm runs in a for loop using the current extent to perform the clip. Saving the OUTPUT to memory works fine ...
0
votes
1
answer
124
views
Shapefile missing spatial reference information when run as a batchfile
I have Python script that needs to pull the ESPG code from a shapefile, when I run this in Intellij IDEA 2021.1.2 (using a Anaconda Environment for Python) it works correctly, but when it is run as a ...
1
vote
0
answers
142
views
Rasterizing vector file in EPSG:4326 using GDAL/OGR in Jupyter notebook
I was trying to rasterize the vector file in Python.
I used this code:
gdal.Grid("trial2.tif", "merged2018-19.gpkg", zfield="h_li", algorithm="nearest")
(the ...
2
votes
1
answer
495
views
Get file extension based on GDAL/OGR Driver
I'm wondering if there is any way of retrieving the correct file extension for GDAL/OGR drivers. For example, if I do something like
from osgeo import ogr
driver = ogr.GetDriverByName('ESRI Shapefile')...
3
votes
1
answer
466
views
ogr2ogr Warning 1: layer names ignored in combination with -sql
When I run ogr2ogr command to export some specific polygons from .osm.pbf file, downloaded from OSM, I get an error Warning 1: layer names ignored in combination with -sql.
I use -sql tag to get get ...
1
vote
0
answers
176
views
Connecting WFS/OGC API - Features(GeoServer) in QGIS using Python [closed]
I made feature count program but it works when shapefile is saved. I want to make the program that connect to server and count features.
I made codes that count features which is saved.
from osgeo ...
3
votes
1
answer
784
views
Dissolving polygons based on polygon attribute values in Python
I have a shapefile, with multiple features inside. I am trying to dissolve the nearby/adjacent features based on the shapefile particular attribute value (gridcode), but the difference shouldn't be ...
0
votes
1
answer
185
views
How to install GMLAS driver, working for OGR command line tool?
Normally I run my OGR SQL syntax within OSGeo4W shell. I want to try out the GMLAS driver, but can´t find a distribution where it´s installed. I´m on windows. How do I install the GMLAS driver, ...
0
votes
1
answer
322
views
Issue when reprojecting shapefile using OSGEO in Python: prj file missing and kernel restart
I tried to reproject a shapefile based on the projection of a raster file following this example (section "Reproject a Layer").
My code is as follows:
# open the raster tif and extract ...
1
vote
0
answers
121
views
Fill shapefile column with raster value, shapefile with alias name and calculated field
I've to sample raster values to fill a column of point shapefile using Python, and for this I've no problem. But this shapefile has some fields with alias name and some fields that result from an ...
1
vote
0
answers
341
views
FileGDB In GDAL Docker container with dot net core
Currently, I am using this docker image pepperlk/gdal that has FileGDB built in and working via command line.
Details here:
gdalinfo --version
GDAL 3.3.0beta1-b75f14ab12155c6b6f4544a9894c41f2f9a7d241, ...
1
vote
0
answers
721
views
Loading a GML file to PostGIS using Python and GDAL vectortranslate: encoding problems
I have some GML files I want to load into my PostGIS database using the GMLAS reader in GDAL in a Python script. The script is run from a batch file. For example this dataset from Geonorge - https://...
-1
votes
2
answers
778
views
ogr2ogr cannot import data
I can successfully get a connection to my remote sql server database using:
ogrinfo "MSSQL:server=my_server_name;database=my_database;Trusted_Connection=True;"
But when I try to import an ...
3
votes
1
answer
466
views
Getting intersecting polygons of points using OGR and Python
I have multiple files that essentially have anywhere from 2000-5000 points each.
I have a polygon file that has about 10000 polygon shapes.
For each file containing the points, I want to get all the ...
0
votes
0
answers
647
views
Reduced/Increased size polygons with Buffering GDAL/OGR
In case somebody needs to do the buffering of geometries (using pure OGR).
I am trying to create reduced/extended polygons from an existing polygon using OGR in Python.
The abstract idea that I have ...
2
votes
1
answer
446
views
GDAL Virtual File Systems Python Opening files in Network Drive Issue
I'm trying to open a .tar file using /vsitar/
The file to be opened is located at: //my_network_drive/scratch/my_file.tar
In Python I have the following snippet:
driver = ogr.GetDriverByName('ESRI ...
1
vote
0
answers
126
views
Implementation for Boolean operations on polygons like union, intersections, contains?
https://en.wikipedia.org/wiki/Boolean_operations_on_polygons#Algorithms
I wish to understand how are Boolean operations on polygons implemented in GIS related geometry libraries. I've tried to go ...
1
vote
1
answer
287
views
Choosing efficient output format for spatial data in R
I'm assembling a moderately large spatial dataset as simple features in R (4.0.5).
Is there a good way to select the most performance-efficient output format/OGR driver to save my assembled data?
I'm ...
2
votes
1
answer
1k
views
Get OSM building heights using height or building:levels tags
I want to parse OSM data and to get all buildings with height or building:levels data.
I changed osmconf.ini file to read height and building:levels tags as separate columns for multipolygon layer but ...
2
votes
0
answers
162
views
Connection pooling in OGR PostgreSQL driver
OGR (GDAL) provides a vector driver for "PostgreSQL" and data in the DB can be accessed with something like the following:
driver = ogr.GetDriverByName("PostgreSQL")
datasource = ...
6
votes
2
answers
8k
views
Create a shapefile from geometry with OGR
As I see from the GDAL/OGR available solutions, most of the new OGR data sources (shapefile etc.) are being created from an already existing similar file. This way many steps of directly creating ...
3
votes
1
answer
512
views
How to batch rename tables in GeoPackage with OGR
I would like to rename all tables in a GeoPackage file. The "translations" are stored in a .csv file.
I would like to do this on the command line and found the below thread that uses the ...
4
votes
1
answer
964
views
GDAL Rasterize with "where" option in Python
I've got a shapefile with set of points with a column "test_class" of String type in the attribute table.
I need to rasterize these points with setting pixel's value for each class and ...
0
votes
1
answer
622
views
OGR reports incorrect SRS for GeoJSON
OGR (GDAL 3.2.2) appears to incorrectly read the SRS of GeoJSON features and I would like to know if there is anything I can do to prevent this.
I have two GeoJSON files and both represent the same ...
0
votes
1
answer
484
views
st_combine and st_union produce empty attribute table for shapefile (how to edit before st_write?)
I am starting with R programming and I am having a hard time figuring out how to edit the attribute table of a shapefile after using st_combine and st_union.
My shapefile has multiple polygons and I ...
1
vote
1
answer
566
views
How to find WFS layer geometry type, when the layer is empty (0 features)?
Is it possible to find the geometry type of a layer in a WFS, using OGR, when the layer is empty (0 features)?
3
votes
1
answer
1k
views
How can I use GDAL installed with QGIS from command line?
I have QGIS 3.10 and I can run GDAL using OSGeo Shell. I want to be able to use GDAL commands from command line. For now, when I run gdalinfo --version I get message 'gdalinfo' is not recognized as an ...
2
votes
1
answer
896
views
Is it possible to create a VRT file with ogr2ogr?
I want to create VRT files from ungridded .asc files (example file).
The VRT files should look like this:
<OGRVRTDataSource>
<OGRVRTLayer name="worms">
<...