New answers tagged

1

1) I just don't know how to convert .geojson file to .shp. This is a one of the bases of ogr Python. If you have a geometry, it is very easy to convert it to a shapefile # geojson is GeoJson Polygon from osgeo import ogr output = "geojson.shp" driver = ogr.GetDriverByName('ESRI Shapefile') if os.path.exists(output): driver.DeleteDataSource(output) ...


1

WKT is only a text markup language for representing vector geometry, therefore you cannot convert 3D WKT to 2D (= text to text), you need to change the geometry The problem with ogr is that it seems that all the geometries are 3D by defaut 1) Creation of a 2D point with ogr point = ogr.Geometry(ogr.wkbPoint) # 2D point point.AddPoint(1198054.34, 648493.09)...


2

This is one of the most common GDAL/OGR Python Gotchas: A dataset is only written to disk after it is closed. Closing a dataset happens when it goes out of scope. This can be done in a number of ways and one of the following needs to be appended to the end of your script. data_out = None data_out = "some new value" del(data_out) There are libraries ...


1

If you want to interact with this data using SQL expressions without loading into a database server (PostgreSQL/PostGIS or SQL Server), try loading the shapefiles into QGIS and use the DB manager plugin. There is a node called "Virtual Layers" > "QGIS Layers" then you will see the shapefiles in your map. You can hit the "SQL Window" button and start writing ...


2

You can install PostgreSQL (opensource) and the PostGIS and TIGER extensions to load the TIGER data. This post has a lot of good info that I used to load the census data. Then you can run SQL queries to get at the data. I loaded all US Data into PostgreSQL on a Win 7 (64 bit) with 8 GB ram and a 230 GB hard-drive (with other apps installed).... I am just ...


0

Yellowcap's answer above worked for me with some minor tweaks: pip install --no-install is no longer an option. Instead, inside the env directory: pip download GDAL==1.11.2 (or whichever version you want) Unzip the downloaded directory and cd into it: tar -zxvf GDAL-1.11.2.tar.gz cd GDAL-1.11.2 pip install --no-download is also no longer an option. ...


1

Got it! An environment variable needs to be set. It can be set either in the shell: export SHAPE_ENCODING="utf-8" or within the script: os.environ['SHAPE_ENCODING'] = "utf-8" I prefer to set it in the script. I tried out various ways of decoding from utf-8 and encoding to ISO8859_1 within the script with no luck. feature.SetField does not accept ...


0

Welcome to the world of Python encodings... The first line of a KML file indicates the character encoding (XML encoding declaration) <?xml version="1.0" encoding="utf-8" ?> In GDAL: KML - Keyhole Markup Language The content returned by OGR will be encoded in UTF-8, after the conversion from the encoding mentioned in the file header is. With ...


1

It's actually much simpler than what you've got going on there. ogr2ogr outputShapefile.shp input.kml Of course you can also use other option to specify srs etc. for example I work alot with a non standard crs, Lowrance Mercator Meter, so I use: ogr2ogr -t_srs "+proj=merc +a=6356752.3142 +b=6356752.3142 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=...


0

My problem now is to make the selected points into a new shapefile. I made new scripts, but I cannot view the selected points. Here is my sample code: from osgeo import ogr, osr import os, sys # Get the input Layer inDriver = ogr.GetDriverByName("ESRI Shapefile") fnVec= raw_input("Enter Filename:") ofn=raw_input("Output Name:") ctype=raw_input("Crime Type:"...


1

I think that with your 'CrimeSQL' request you have all desired features selected. You don't need the 'GetNextFeature' method. To test my approach, I created your fields 'Year' and 'Crime_Type' in my point shapefile of next image. There are only two features with attributes ('2011', 'Robbery') at attributes table (delimited by red rectangle). Your code ...



Top 50 recent answers are included