Tag Info

Hot answers tagged

9

You miss a minus sign before where and the select is not necessary, so it should be: ogr2ogr -where ID="1" outfile.shp infile.shp or if you have to do more complex query on your input data: ogr2ogr -sql "SELECT * FROM infile WHERE ID='1'" outfile.shp infile.shp If ID is a field of Integer type, substitute ID='1' with ID=1. Notes: -f "ESRI Shapefile" ...


8

Why not work globally ? calculate the distances between all points union the resulting lines pointx - pointy with a distance < 14m I will use Shapely, much easier for resolving these kinds of problems. You must iterate through all pairs of points to calculate the distance once (as distance point1-point2 = distance point2-point1). There are many ...


8

The ogr2ogr utility supports a limited sql syntax. You can join your CSV to the shapefile using something like the following: ogr2ogr -sql "select inshape.*, joincsv.* from inshape left join 'joincsv.csv'.joincsv on inshape.GISJOIN = joincsv.GISJOIN" shape_join.shp inshape.shp


5

I had to solve the same problem today, so here is my answer, which gives a complete solution: I have a lineWKT.csv file stored in F:\Data\ folder, with the data like this: id,gm 0,"LINESTRING (30 10 0, 10 30 0, 40 40 5)" I have a vrt file like this: <OGRVRTDataSource> <OGRVRTLayer name="lineWKT"> ...


5

You can solve with two chained VRT files and a bit of OGR SQL. The first VRT (e.g. remapped_csv.vrt) is: <OGRVRTDataSource> <OGRVRTLayer name="remapped_csv"> <SrcDataSource>test.csv</SrcDataSource> <SrcSQL>SELECT *, SUBSTR(latlon,2,5) AS lat, SUBSTR(latlon,9,12) AS lon FROM test</SrcSQL> ...


5

It is easy: from osgeo import ogr import os driver = ogr.GetDriverByName("ESRI Shapefile") if os.path.exists('your.shp'): driver.DeleteDataSource('your.shp')


5

ogrinfo can shorten the output considerably using the -so flag. -so: Summary Only: supress listing of features, show only the summary information like projection, schema, feature count and extents. So ogrinfo -ro -so file.shp should give a summary of the metadata. And -al: List all features of all layers (used instead of having to give layer ...


5

When you start with a Python module, there are several solutions to find the available functions. One of them is dir: geom = feat.GetGeometryRef() print dir(geom) ['AddGeometry', 'AddGeometryDirectly', 'AddPoint', 'AddPoint_2D', 'Area', 'AssignSpatialReference', 'Boundary', 'Buffer', 'Centroid', 'Clone', 'CloseRings', 'Contains', 'ConvexHull', 'Crosses', ...


4

ogr2ogr is part of the Geospatial Data Abstraction Library (GDAL). Get homebrew from http://brew.sh brew install gdal


4

Taking the information from the above, here's how you would actually get the ogr2ogr command working like it should add this to your ~/.bash_profile script: export PATH=/Library/Frameworks/GDAL.framework/Versions/1.[YOURVERSIONHERE]/Programs/:$PATH the above code also adds a bunch of other gdal libraries to your path as well


4

As it already has been mentioned in comments to your questions, MapInfo Professional does require the table to be added to the MapInfo.MapInfo_MapCatalog. This table tells MapInfo Professional how to handle and display the spatial part of the table. You do however not need to use EasyLoader to load your table - you can do it with other tools, too. But you ...


4

Within the database, geometries are stored on disk in a format only used by the PostGIS program. In order for external programs to insert and retrieve useful geometries, they need to be converted into a format that other applications can understand. Fortunately, PostGIS supports emitting and consuming geometries in a large number of formats: from ...


4

The Ogr function GetEnvelope() returns "a tuple (minX, maxX, minY, maxY)" (from here), but what you want (from what I can understand) is a Polygon describing the envelope/bbox? This is actually rather simple, as the tuple (minX, maxX, minY, maxY) is all you need to create a Polygon. Just create a Polygon based these, like so: from osgeo import ogr def ...


3

AFAIK OGR SQL doesn't support regular expressions natively, but... By default, the REGEXP operator has no implementation in SQLite. With OGR >= 1.10 built against the PCRE library, the REGEXP operator is available in SQL statements run by OGR. Source: http://www.gdal.org/ogr/drv_sqlite.html However, see also: ...


3

A trick you can use is to use the Intersect tool on a single layer. So inputs could be: After the Intersect tool has been run you get this polygon layer from which you can extract centroids:


3

If you want to use the Kyngchaos's version of QGIS, you should use his version of GDAL/OGR (Framework in /Library/Frameworks/GDAL.framework). This version also installs the Python osgeo module (in /Library/Python/2.7/site-packages because QGIS use the Apple Python). If you want to use the Homebrew version of GDAL/OGR (library in /usr/local/Cellar with ...


3

You must understand the PATH and the $PATH variable on POSIX and Unix-like operating systems (as Mac OS X, look at The PATH Variable) and BASH The GDAL programs of Kyngchaos, as Laurent Jégou says, are installed in /Library/Frameworks/GDAL.framework/Versions/1.10/Programs/ so, in the terminal, use the command: export ...


3

You'll want to use ST_AsBinary(geom) to convert your geometry from the PostGIS internal format to WKB that you can read with ogr: cur.execute('SELECT ST_AsBinary(geom) FROM mytable LIMIT 1') result = cur.fetchone() In Postgres terms, your result is a bytea. The psycpopg2 library will map this to a memoryview Python type: >>>> type(result[0]) ...


3

In pure Python, without using the subprocess module (os.system is deprecated) to call ogr2ogr or shp2pgsql, for example): 1) with ogr Append a shapefile to a postgis table using the GDAL/OGR Python interface 2) with ogr and psycopg2 from the book Python Geospatial Development (Eric Westra), Chapter 7, p.219 import os.path import psycopg2 import ...


3

If you have a Polygon you can get the number of rings using geometry.GetGeometryCount() The first ring is the outer ring, the following rings are inner rings (aka holes). Here a small script: print "Next polygon:" nbrRings = geometry.GetGeometryCount() for i in range(nbrRings): print geometry.GetGeometryRef(i) The output for the following polygons ...


3

You're trying to use an OGR (vector) driver with GDAL (raster) tools. Here's a few lines of my working code that may help: char* BasePath = new char[FullPathMax]; // this does have a value before it's used OGRRegisterAll(); OGRDataSource *hDS = NULL; OGRSFDriver *Driver = NULL; hDS = OGRSFDriverRegistrar::Open(BasePath,FALSE,&Driver); As you can ...


2

I suggest adding to the end of your script:- o3_proj.Destroy() o3_proj = None As from other OGR tutorials I've read when working on my scripts, these calls at the end are suggested as necessary to ensure not just memory release, but also writing out data. Let us know how it goes - as your use of SetFeature() does appear correct as far as I can tell. And ...


2

Gross, but: del lyrBuffer del ds # flushes Buffer.geojson to disk ds = GeoJSONDriver.Open('Buffer.geojson', 0) lyrBuffer = ds.GetLayerByIndex(0) print lyrBuffer.GetFeatureCount() From what I can tell, OGRGeoJSONDataSource.CreateLayer() returns a OGRGeoJSONWriteLayer, not a OGRGeoJSONLayer (which is what you get when opening an existing file). The former ...


2

Use the ogr.Layer.ResetReading() method. bufferfn = ogr.Open('buffer_stands.shp') buffer_lyr = bufferfn.GetLayer() roadfn = ogr.Open('OSMroads.geojson') road_lyr = roadfn.GetLayer() for buffer_feat in buffer_lyr: buffer_geom = buffer_feat.GetGeometryRef() print 'buffer' for road_feat in road_lyr: road_geom = ...


2

Not really understand what you want to achieve To make it work, just move roadfn = ogr.Open('OSMroads.geojson') road_lyr = roadfn.GetLayer() t one line before for road_feat in road_lyr: an the loop The point here is "think of road_lyr as a variable when you loop that empty itself (for memory purpose)" You can just confirm this by doing: import ogr ...


2

ptrv/gpx2spatialite does this remarkably well, saving timestamps for all points and deriving speed and length data for tracks. It also won't import duplicate tracks, so you can feed it a huge pile for GPX files and it will munge them appropriately. Update: usage examples, as requested: Initialize new database: gpx2spatialite_create_db db.sqlite Add a ...


2

For instance, in Python there aren't any import method (importFromWkt). ??? -> Look at the ogr module content: from osgeo import ogr print dir(ogr) [..., 'CreateGeometryFromJson', 'CreateGeometryFromWkb', 'CreateGeometryFromWkt','CreateGeometryFromGML',...] and the Python GDAL/OGR Cookbook 1.0 documentation: wkt = "POINT (1120351.5712494177 ...


2

There are some errors in your script but it is not the most important problem: You cannot create a valid shapefile without specifying the geometry of the layer: driver = ogr.GetDriverByName('ESRI Shapefile') dstshp = driver.CreateDataSource('SomeFilename.shp') dstlayer = dstshp.CreateLayer('mylayer',geom_type=ogr.wkbPolygon) And you don't know a priory ...


2

These are a few things I noticed, your Python 2.7.3, installed with ArcGIS, is 32 bit while the filegdb plugin is 64 bit. You may need a 64 bit Python to match the filegdb driver. Also, you installed two versions of GDAL 32 bit & 64 bit, this might be ok. When you import osgeo, which version are you importing, 32 or 64? Your GDAL_DRIVER_PATH points to ...


2

You may try: ogrinfo -al USA_adm0.shp >> output.txt All the information will be redirected into a text file called output.txt, in the same folder which contains the ogrinfo utility



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