Wednesday, August 24, 2016

Geoserver slice string values using SLD for label manipulation


I have an attribute column in my PostGIS polygon table and want to only show the first 2 characters of this text field on my label using SLD in Geoserver.  My goal is to place the label at the center of the polygon so here it goes in SLD xml syntax as usual very verbose and ugly.

<TextSymbolizer>
            <Geometry>
              <ogc:Function name="centroid">
                <ogc:PropertyName>geom</ogc:PropertyName>
              </ogc:Function>
            </Geometry>

          <Label>
              <ogc:Function name="strSubstring">
                  <ogc:PropertyName>short_name</ogc:PropertyName>
                  <ogc:Function name="parseInt">
                    <ogc:Literal>0</ogc:Literal>
                  </ogc:Function>
                  <ogc:Function name="parseInt">                            
                      <ogc:Literal>2</ogc:Literal>
                  </ogc:Function>
              </ogc:Function>
          </Label>
                   
</TextSymbolizer>

My table column name is "short_name"  and the geometry column name is "geom".  This works and creates my label in the center of the polygon only drawing the first 2 characters from the field "short_name".

I hope this helps :)
cheers
Michael

Friday, January 8, 2016

Goals for 2016

This year I want to start out with a bang and what better way to start the year off right than setting up some goals for 2016.  I think 5 goals should be reasonalble to achieve.

Goals 2016


  1. Do more Django coding
  2. Learn better Javascript best practises
  3. Write more blog posts
  4. Complete two spare time projects for fun
lets check this out again in January 2016 and see what gets done.

cheers

                                                                                                                                                                                                                                            

Tuesday, January 5, 2016

Python Geospatial Analysis Cookbook now available

Python Geospatial Analysis Cookbook

Well almost 1 year has past and my book is finally available for purchase.  For those of you visiting this blog you habe 2 awesome choices to get the book at a great discount.

Exclusive deal 50% off with this code:





Packt is also offering a great deal to get my book and many more at only 5$ !! click below





Wednesday, November 11, 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",0.0174532925199433,
            AUTHORITY["EPSG","9122"]],
        AXIS["Latitude",NORTH],
        AXIS["Longitude",EAST],
        AUTHORITY["EPSG","4326"]],
    PROJECTION["Mercator_1SP"],
    PARAMETER["central_meridian",0],
    PARAMETER["scale_factor",1],
    PARAMETER["false_easting",0],
    PARAMETER["false_northing",0],
    UNIT["metre",1,
        AUTHORITY["EPSG","9001"]],
    AXIS["X",EAST],
    AXIS["Y",NORTH],
    EXTENSION["PROJ4","+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0
    AUTHORITY["EPSG","3857"]]
FID Column = PK_UID
Geometry Column = geom
Text: String (0.0)
spacetype: String (0.0)
building: Integer (0.0)
floor: Integer (0.0)
type_id: Integer (0.0)
tag: String (0.0)
name: String (0.0)

Now you see we have a total of 9 Columns
 using the -fieldmap option of ogr2ogr we can only input 7 of those fields.. The FID Column and Geometry Colung do NOT count towards the -fieldmap list

-fieldmap 7,4,6,9,10,3,2

This means  7 = field Text,  4 = field spacetype, 6 = building, 9=floor, 10=type_id, 3=tag, 2=name

the value 7 for example represents the column position in your PostgreSQL DB where you want to import INTO using the Spatialite Column called "Text" in this example.

Counting the column number in Postgresql is also hard.  You start at 0 NOT including the Primary Key and excluding the Geometry column where ever it is the the column order.



Thursday, August 6, 2015

Python Geospatial Analysis Cookbook coming soon...

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

Tuesday, June 30, 2015

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


Saturday, June 6, 2015

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:

  1. NULL value in field
  2. '' empty in field
  3. .dbf encoding  (Latin1, UTF-8)
Anyway if you know of a cause please let me know.

cheers
michael