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

Avoiding the spatial query Since you noted buffering is computationally expensive and may be holding you back, consider this approach: Start looping through each point and round off your lat long point to a decimal place within your buffer (i.e. if your lat/long is 12.3456789/12.3456789 then get all points that begin with a lat/long of 12.34567/12.34567 or ...


5

Looks like ogr2ogr has support for exactly this problem. The below is copied directly from that page: How do I flip coordinates when they are not in the expected order The EPSG has a recommanded order for geographic SRS where the coordinates tuples of a geometry must appear in the (latitude, longitude) order, whereas most GIS will properly display such ...


5

The second argument in Open specifies if the data can be updated (written to). Try: dataSource = driver.Open(fn,1)


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

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

I've gotten this working on my 10.1 system, at least somewhat (I can run import ogr from the ArcGIS python window and it appears to be working). First I attempted to get my system as clean as possible. I uninstalled previous versions of GDAL (from OSGeo4W). I do still have PostgreSQL+PostGIS which has it's own version of GDAL, but I can't uninstall that (I ...


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

Quoting the shapefile specification (page 4): All the non-Null shapes in a shapefile are required to be of the same shape type. You may choose point OR multipoint OR polygon, but you cannot use multiple geometry types in a single shapefile. Multi-part geometries are permitted in all flavors of multipoint, polyline, and polygon shapefiles.


3

It doesn't look like it is included in the most recent GDAL-Complete framework. Please file a request with kyngchaos.com. In the meantime, if you don't mind trying it yourself, you can attempt to build a shared plugin for GDAL 1.10, install it, and see if it works with your data source: Ensure you have XCode and/or its command line tools installed. ...


3

len() is a pure Python function that return the length (the number of items) of an object (whatever the object) -> in this case the number of features. .GetFeatureCount() did the same thing (number of features in the layer) but has some additional functions compared to the simple len(). It is based on the CPP OGRLayer::GetFeatureCount() function (in the ...


3

I tried this example and I got different results. For a shapefile containing a layer with 246 features, the running time was 304usec per loop on GetFeatureCount(), while it was 315usec per loop on len(layer). Timeit used 1000 loops to evaluate this. This was done using: testFeatureCount.py import osgeo.ogr def testFeature(): shapefile = ...


3

ogrinfo as nothing to do with Visual Studio. It is a command line tool (Windows, Linux, Mac OS X) So you use it in the Windows console or in the Linux and Mac OS X shell in the same way. ogrinfo yourshape.shp with a lot of options: (ogrinfo) And, there are many, many tutorials in Gis.StackExchange : search ogrinfo and on the Web....


3

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


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

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

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

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


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

If the lat/lon extents of the raster are around longitude range: -80 to -20 latitude range: -40 to +10 That is, most of South America extending into the Atlantic Ocean. You could try to use the well-known text below. The ogr2ogr help page says that you can specify WKT or a file that contains WKT (the latter is easier) if there's no EPSG WKID. ...



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