Thursday 12 January 2017

Mapnik Style Filter on River/Lakes Shapefile attributes (from Natural Earth Data)


As a followup to this question, I downloaded the vector data here:




and I successfully created the rasterized water/land mask I wanted:



However, there are too many rivers at this level.


Question


Can I/how do I make use of the scale information in the 10m_rivers_lake_centerlines_scale_ranks.dbf file?


Details


(Part of this dataset)


Note I can open the .dbf file in a text editor and see loads of interesting and hopefully useful data:


...

River 0.300000012
River Pivd. Buh 8 670670
River 0.349999994
River Pivd. Buh 8 670670
River 0.200000003
Lake Centerline Klarlven 8 677677
Lake Centerline 0.250000000
Lake Centerline Klarlven
...


(this is a random chunk of binary formatted by removing spaces and adding newlines)


Using Nik2Img.py I run the following XML and get the overrun-with-rivers-results:














landstyle


shape
../10m/10m_land




landstyle

shape

../10m/10m_minor_islands







riverstyle

shape
../10m/10m_rivers_lake_centerlines_scale_ranks






Changing the appropriate riverstyle section to the following eliminates all rivers/lake centerlines instead of filtering anything by type (River vs. Lake Centerline) or scale/rank/thickness:


  

How do I/can I make some filter(s) for this?


      [River] >= 0
[River] > 0

I'm new to Mapnik and Natural Earth Shapefiles. I'm an experienced programmer so I'm willing to write code (Python, C#, etc.) if I need to but I'd like to use the tools available if possible.



Answer



The attribute 'River' does not exist in that shapefile as far as I can tell. Your post helped remind me that Mapnik should be throwing an error in this case, so it is easier to catch common typo's like this (http://trac.mapnik.org/ticket/604).


A trick to get the attribute names is to open the Shapefile in QuantumGIS (and even use the Quantumnik Plugin if you want an xml snippet generated for Mapnik) or use ogr2ogr to query the shapefile like:




$ ogrinfo 10m_rivers_lake_centerlines_scale_ranks.shp -so -al
INFO: Open of `10m_rivers_lake_centerlines_scale_ranks.shp'
using driver `ESRI Shapefile' successful.

Layer name: 10m_rivers_lake_centerlines_scale_ranks
Geometry: Line String
Feature Count: 4078
Extent: (-164.903495, -52.157769) - (177.211192, 75.793463)
Layer SRS WKT:

GEOGCS["GCS_WGS_1984",
DATUM["WGS_1984",
SPHEROID["WGS_1984",6378137.0,298.257223563]],
PRIMEM["Greenwich",0.0],
UNIT["Degree",0.0174532925199433]]
StrokeWeig: Real (19.9)
FeatureCla: String (32.0)
Name1: String (254.0)
Name2: String (254.0)
ScaleRank: Integer (10.0)

RiverNum: Integer (10.0)
Dissolve: String (100.0)
Note: String (50.0)

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...