Tag Info

Hot answers tagged

5

To process large files, you need to use a generator which only read/write one line at a time and Python has a command that does that: with. The with statement handles opening and closing the file, including if an exception is raised in the inner block. The for line in f treats the file object f as an iterable, which automatically uses buffered IO and ...


4

This is a GDAL/OGR Python gotcha. So when you use print inputlyr[0].GetGeometryRef(), the reference to the indexed feature has been cleaned up before geometry functions can be used. This is expected behaviour, and there is no roadmap to change it. The issue is that the GDAL/OGR Python bindings are over a decade old, and are tightly coupled with the ...


4

Some remarks because you mix many things ( if you want yo use your script outside the console of QGIS, install the Python module GDAL (osgeo) in your Python installation: it is installed in the Python version of QGIS if you are on Windows). 1) There are no Shapely geometries in your script, only PyQGIS geometries QgsPoint(x_min, y_min), ... ogr geometries ...


4

Python does not contain a separate library for GDAL but rather bindings to access the GDAL libraries. As GDAL is updated so are the affected bindings, ensuring that you'll have full access to GDALs functionality from Python. If you upgrade GDAL you will also upgrade the Python bindings (if the version you upgrade to supports Python bindings). If you build ...


3

Resolved! It's a module PATH Python console problem. In QGIS Brighton/apps/Python27/Lib/site-packages create osgeo.pth (Administrators) file and put # .pth file for the osgeo extensions osgeo start QGIS and install flowmapper ;) Clarifying, after create osgeo.pth file, open him and just add in first line the word osgeo, save and run QGIS! Done.


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


3

I used the ogr java bindings: public static void unitOfCRS(){ SpatialReference poSourceSRS = new SpatialReference(); // output: metre poSourceSRS.ImportFromEPSG(3068); System.out.println(poSourceSRS.GetAttrValue("UNIT")); // output: degree poSourceSRS.ImportFromEPSG(4326); ...


3

A python solution is fairly simple using ogr.GetDriverByName(in_format).Open(in_file). import sys from osgeo import ogr def main(in_file, in_format, out_file, out_format): in_ds = ogr.GetDriverByName(in_format).Open(in_file) out_ds = ogr.GetDriverByName(out_format).CopyDataSource(in_ds, out_file) if __name__ == '__main__': main(*sys.argv[1:]) ...


3

Assuming you have an older version of GDAL/OGR, you can use OGR SQL to cast the geom field to a geometry. For example: ogr2ogr -f "ESRI Shapefile" "sample.shp" "geo.csv" -sql "SELECT *, CAST(geom as geometry) FROM geo" This will create a new shapefile using the WKT data as the geometry. You can use the same query with ogrinfo as well: ogrinfo -ro -sql ...


2

Your 'ENGL_NAME' shouldn't be abbreviated at all (less than 10 characters), but writeOGR has its own will, it seems. Instead of writeOGR(shp, "PolygonsV2", speciesname, driver="ESRI Shapefile") you might try currdir <- getwd() #store your current working directory setwd(paste(currdir,"PolygonsV2",sep="/")) #switch to your desired folder ...


2

You have many solutions but you choose to use ogr and the GeoJSON format (you could have chosen Fiona and shapely or one of the many modules to parse gpx files: Pypi:gpx or to parse XML files). 1) Is there a more direct or idiomatic way to create this rectangle? ogr is is verbose, look at Python GDAL/OGR Cookbook With the GeoJSON format: import json ...


2

Turns out it is as easy as this: MIMETYPE "application/json; subtype=geojson; charset=utf-8" Without the setting, no content encoding is returned by the server.


2

Stepping back, if you have data in PostGIS and you want to render it with Mapnik you really should be using Mapnik's native PostGIS support - aka mapnik.PostGIS datasource in python (https://github.com/mapnik/mapnik/wiki/PostGIS). That will be faster and more efficient than going through OGR. That said, if you have a good reason for connecting to PostGIS ...


2

Depending on your version of mapnik, yes it's possible. Mapnik 2.1 introduced the Python Plugin as a data source. You would need to subclass mapnik.PythonDatasource and implement a features method that based on an incoming mapnik.Query object will return mapnik.PythonDatasource.wkb_features objects. For example: import mapnik import ogr class ...


2

You on Linux? If so, switch all the single quotes for double quotes and vice versa like this: ogr2ogr -f GeoJson -where 'neighborhood IN ("Lower East Side", "Greenwich Village", "Columbia St", "Financial District", "Flatiron District", "Williamsburg", "West Village", "Central Park", "Upper West Side", "Navy Yard", "Gramercy", "Stuyvesant Town", "Upper East ...


2

Just figured out a way to do this in R, inspired by the link I posted in the comments (which uses outdated functionalities but the right packages); as an example, I'll use the "Southwesternmost" counties in Michigan (shapefile here--Allegan, Berrien, Cass, Kalamazoo, St. Joseph, and Van Buren counties) So, ordering counties alphabetically, the (length>0, ...


2

In order to use this data in PostGIS or another system you need to convert the start-center-end arcs into start-midpoint-end arcs. This is actually pretty easy. In vector terms, you subtract the center from the start- and end-points. Now you can get the mid-point of the arc by adding the start- and end-points together, then normalizing to the radius of ...


2

Don't expect OGR to be Pythonic. In fact, there is a large list of gotchas documented to describe these. Essentially, all of the variables are references to objects described in C++, so they often don't make sense with workflows in Python. Modules like copy only work on Python objects, which is why your example doesn't work as expected. You need to keep ...


2

That solved my problem. Further information and a tutorial can be found here http://gdal.org/1.11/ogr/ogr_apitut.html A C++ version for GDAL 1.11: #include <GDAL/ogrsf_frmts.h> int main() { OGRRegisterAll(); OGRDataSource *poDS; poDS = OGRSFDriverRegistrar::Open( "data.shp", FALSE); }


2

You can test it with gdalsrsinfo http://www.gdal.org/gdalsrsinfo.html gdalsrsinfo epsg:3068 PROJ.4 : '+proj=cass +lat_0=52.41864827777778 +lon_0=13.62720366666667 +x_0=40000 +y_0=10000 +ellps=bessel +towgs84=598.1,73.7,418.2,0.202,0.045,-2.45 5,6.7 +units=m +no_defs ' OGC WKT : PROJCS["DHDN / Soldner Berlin", GEOGCS["DHDN", ...


2

A MultiPoint, by definition, comprises several points, so geom = '{"type": "MultiPoint", "coordinates": [[100.0, 0.0], [101.0, 1.0]]}' geom = ogr.CreateGeometryFromJson(geom) # iterate through the points for i in range(0, geom.GetGeometryCount()): g = geom.GetGeometryRef(i) print "%d,%d" % (g.GetX(), g.GetY()) 100,0 101,1 as explained in Iterate ...


2

If you only want the point coordinates, you don't need Shapely, simply use the appropriate key of the dictionary: for point in filter_list: print point['geometry']['coordinates'] (270977.604378, 153144.810665),... If you want a Shapely geometry, use the shape function of Shapely: from shapely.geometry import Point, shape for point in filter_list: ...


2

Your capital_pt is the coords attribute of the original capital shapely geometry object. In itself this is not a shapely geometry, rather a sequence of tuples of flots which are the point objects. Instead you should be using distance_between_pts = capital.distance(city_items) Given your case where you're trying to calculate distances for all points in a ...


2

Since OGR version 1.10.0 the sqlite SQL dialect has been able to be applied to any spatial datset. Which is great, as it means that you can apply it to your GeoJSON files. Looking at the OGR GeoJSON documentation you can see that the layer name for a GeoJSON file is OGRGeoJSON which means that the SQL that selects from the GeoJSON file will translate from ...


2

You could try the OGR WFS option "-dsco OGR_WFS_PAGING_ALLOWED=ON" as described in the docs http://www.gdal.org/drv_wfs.html


2

If you are using Linux, you should be able to connect to a WFS server, and fetch a layer without any problem with wget. I was able to fetch a dataset consisting of 10209 features, which was 33.3 MB in size. My test command was the following: wget -O output.gml ...


2

potentially a multi-part question - 1) plotting grids with legends, 2) including shape files on grid, and 3) animate output images. each with multiple opportunities to accomplish the task. here's a quick run-down of at least 2-methods: using gdal, one should be able to read in the raster - perhaps something like (in a loop to get all rasters). raster = ...


2

There is no projection problem here Shapely uses a cartesian plane system for computing geometries and the result is an unary_union of the original geometry (without any reprojection: "Shapely does not support coordinate system transformations. All operations on two or more features presume that the features exist in the same Cartesian plane", Shapely ...


2

Looking at GDAL autotests, I see only the refresh token is defined. As far as I understand the code, the access token will be automatically got from the refresh token (since the access token is apparently renewed from the refresh token, so it is not practical setting its value directly). So try to undefine the access token ("GFT:" as connection string), and ...


1

Have you seen this snippet: Modify Features It is possible to either change feature’s geometry or to change some attributes. The following example first changes values of attributes with index 0 and 1, then it changes the feature’s geometry fid = 100 # ID of the feature we will modify if caps & QgsVectorDataProvider.ChangeAttributeValues: ...



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