Posts

Showing posts from 2015

How to import Spatialite into PostGIS using ogr2ogr

GOAL: Import a Spatialite table into an existing PostGIS table appending (inserting) new rows using ogr2ogr. The trick is we want to map the fields to import to the correct corresponding PostGIS columns.  First get the list of Spatialite fields using ogrinfo  ogrinfo somedb.sqlite sqliteTableName INFO: Open of `..\sqlite\socgen-db-final.sqlite'       using driver `SQLite' successful. Layer name: e00_poly_join Geometry: Polygon Feature Count: 60 Extent: (-168613.719162, 5983831.402051) - (-168508.270008, 5983961.187764) Layer SRS WKT: PROJCS["WGS 84 / Pseudo-Mercator",     GEOGCS["WGS 84",         DATUM["WGS_1984",             SPHEROID["WGS 84",6378137,298.257223563,                 AUTHORITY["EPSG","7030"]],             AUTHORITY["EPSG","6326"]],         PRIMEM["Greenwich",0,             AUTHORITY["EPSG","8901"]],         UNIT["degree"

Python Geospatial Analysis Cookbook coming soon...

Image
Hi, My book titled:   Python Geospatial Analysis Cookbook is coming soon Author: Michael Diener https://www.packtpub.com/big-data-and-business-intelligence/python-geospatial-analysis-cookbook I am proud of my work and now the last stretch is ahead getting the last corrections, updates, reviews, comments all worked through to make it awesome. Stay tuned for any updates. cheers Michael

Geoserver create a new layer using REST API

I'am using Geoserver since, well a long time now.  This post is going to be a collection of THINGS that you might want to do with Geoserver.  Sometime errors occur when trying to do something with Geoserver with the REST API and those I have posted aswell. Goal adding a PostGIS table using the Geoserver REST API COMMAND: curl -v -u yourUserName:PWD -XPOST -H "Content-type: text/xml" -d "<featureType><name>TABLENAME</name><nativeCRS>EPSG:3857</nativeCRS><srs>EPSG:3857</srs><enabled>true</enabled></featureType>" http://localhost:8080/geoserver/rest/workspaces/YOURWORKSPACENAME/datastores/DATASTORENAME/featuretypes Errors   :java.io.IOException: Error occured calculating bounds for someTableName SOLUTION_  permissions on PostGIS tables were incorrect same user as registered in the DB connection must be used when creating a new layer

How to fix pyshp error reading shapefile

I had a Shapefile I was trying to read using the great pyshp library but it kept shooting out and Invalid Argument Error. After some web searching it came down to pyshp being very picky about the Shapefile format.  The true cause I still do not know what was wrong.  My Shapefile was created using QGIS, has valid geometries and no problems identifiable in ArcGIS or QGIS.   Due to other experiences using pyshp sometimes if a field value is NULL or empty it causes some error. The solution: ogr2ogr  new_shapefile.shp original.shp the new_shapefile.shp  will work using the pyshp   ShapeRecords()  function. Possible other problems that pyshp sometimes encounters: NULL value in field '' empty in field .dbf encoding  (Latin1, UTF-8) Anyway if you know of a cause please let me know. cheers michael

GeoDjango < 1.7 return GeoJSON passing model name in request

I thought this might be hard but it really was not.  Django 1.8 introduced GeoJSON serializer so use that if you are starting a new project with Django version 1.8 up.  For those stuck with Django version <=1.7  this is the solution for you. The problem: You want to pass a model name to a request and return the GeoJSON for some map application. pip install django-geojson add 'djgeojson' to your INSTALLED_APPS in the settings.py urls.py   add the URL for example:  here we limit the model name to an alpha numeric characture including underscore or dash that is between 5 and 50 characters long url(r'^geojs/(?P<geomodel_name>[-\w]{5,50})/$',geoview.get_geojson, name="get_geojs"), views.py  should look something like this: def get_geojson(request, geomodel_name):     '''     Pas model name as string     :param geomodel_name: model name as string     :return: instance of model     '''     mymodel = apps.get_mod

ogr2ogr Append new Shapefile to existing PostGIS table

Ogr2ogr is simply powerful.  It is like salt in cooking you use it everyday. The task how to import a Shapefile into a PostGIS table that exists without overwriting the existing table and simply append some new geometries and match the attribute fields from the Shapefile to the PostGIS table fields. There are lots of things I want to do in this import so lets list off what exactly: append new geometry to an existing PostGIS table from a source Shapefile specifiy the source Shapefile projection, because sometimes ogr2ogr guesses wrong define which attribute fields map to which PostGIS table fields specify a non default PostgreSQL schema, in my case the schema=geodata specify the geometry type for output destination as MultiLineString even though my input Shapefile is  a simple Linestring Here is the monster long command line arguments for OGR2OGR: ogr2ogr -update -append -fieldmap -1,-1,2 -a_srs EPSG:900913 -nlt MULTILINESTRING -lco "SCHEMA=geodata" -f Postgre

AutoCAD import x,y,z csv data points

How to import a text file of CSV data with x,y, z  3D points. I though this might be hard but its really not.  The most work is in preparing the data. Create a clean CSV text file with only x,y,z values like this with NO headers: 521864.4,162152.5,447.17 521870.7,162152.7,447.12 521877.9,162153,447.11 521884.8,162153,447.16 521891.4,162153,447.13 the first column is the X coordinate, second column is the Y coordinate, and the third column is the Z coordinate, all separated by a comma  , it is important to note that I am using ACAD 2011 German (Deutsch).  This means your coordinates must be with a .  decimal separator NOT a comma, which is normally the case with German coordinates and numbers.    2. Open ACAD with an empty template    3. Click create POINT    4. Copy the text file contents with STRG-C     or CTRL-C on english keyboard    5. Then PASTE directly into the command line with STRG-V  or CTRL-V    6. Hit escape    7. Save your new DWG  wit

Django GeoDjango deploy on windows server 2012 R2 IIS 8

Image
The battle is set me vs IIS on Windows Server 2012 R2!! Battle Description :  install django 1.7.4, geodjango on IIS 8.5 Lets start with a BIG thanks to cstoker as   http://www.youtube.com/watch?v=kXbfHtAvubc  this was the best starting point to my adventure.  Please watch this video first.  Then follow along to install the remaining magic steps to get geodjango working on your windows server with IIS. 1. Install OSGeo4W First you must INSTALL OSGeo4W   http://trac.osgeo.org/osgeo4w/   and install using custom methods to only select the "libs" gdal and co.  See GeoDjango install instructions here  https://docs.djangoproject.com/en/dev/ref/contrib/gis/install/#windows  2. Update environment variables Then all you need to update are the environment variables .  Like here Screenshots below ! 1.  WSGI_HANDLER                            django.core.wsgi.get_wsgi_application() 2. GDAL_DATA                                   C:\OSGeo4W64\share\gdal     PROJ_LIB