Tag Info

Hot answers tagged

9

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


6

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


6

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


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

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

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


4

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


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

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

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

I suspect the issue is the GDAL 1.11 bindings you're fetching from gohlke do not match the internal GDAL inside of Arc*. Your bindings need to be compiled against ESRI's GDAL to work reliably. It's possible they can be made to work, but it is going to be a lot of headache. In short, ESRI needs to provide the gdal_i.lib stub file that GDAL generates as part ...


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


3

Numbers in any programming language does not have "absolute" precision. As they must be represented as bits in the computer hardware its precision is limited. Anyway review this links, because maybe they can help you: http://comments.gmane.org/gmane.comp.gis.gdal.devel/19331 http://lists.osgeo.org/pipermail/gdal-dev/2011-August/029793.html


2

I ran into this exact problem because I hadn't extracted the zip file into the working directory. I was rushing to get the files converted and when I checked to make sure they were there, the "preview" that I got when I double-clicked on the zipped file tricked me into thinking they were available for conversion. Even if this wasn't the solution to your ...


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

Seems to be working with maptools. Loading the fixed shapefile as per your code: download.file("http://www.personal.leeds.ac.uk/~georl/egs/lnd-stns.zip", "lnd-stns.zip") unzip("lnd-stns.zip") lndS.fix <- readOGR(".", "lnd-stns", p4s = "+init=epsg:27700") plot(lndS.fix) OGR data source with driver: ESRI Shapefile Source: ".", layer: "lnd-stns" with 2532 ...


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

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

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

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

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


2

If the data should cover whole of Spain, I see no problem with the negative coordinate. You will get more distorsions at the edges, but the map should work, until you don't have points on the backside of the globe. This should be the map extent, together with the UTM zones: The extent covers UTM zones 29 to 31, so UTM zone 30 is a good choice for a ...


2

Internally, PostGIS stores geometries in a binary specification, but it is queried and viewed outside as a hex-encoded string. There are two popular variations of well-known binary (WKB): EWKB (via ST_AsEWKB) - an extended WKB specification designed by PostGIS. OGC WKB (via ST_AsBinary) - specified by the OGC and ISO. For a while it was 2D-only, but later ...


2

Not a direct answer using python GDAL bindings but I have used the python subprocess module to call the GDAL command line utility to batch load Shapefiles into into postGIS. Something like this would work: for shapefile in shp_list: program = "C:\Path\to\GDAL" command = 'ogr2ogr -f "PostgreSQL"-overwrite PG:"host=myserver port=54321 user=user ...


2

If you are trying to calculate correct distance by projecting geographic coordinates (lon-lat) to map coordinates (E-N) and then using plane coordinate geometry, then you either need to project using an appropriate equidistant map projection -- probably not a good idea if you have points at arbitrary locations and distances in arbitrary directions or ...



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