Smathermather's Weblog

Remote Sensing, GIS, Ecology, and Oddball Techniques

Archive for September, 2011

Looping Trails– alternate routing for recreational use (cont.)

Posted by smathermather on September 29, 2011

I’ve been thinking more about the recreational looping problem, given a start location and a given range of travel (e.g. 0-3 miles). A way to approach this is to build up loops from a set of nodes to which has been applied a traveling salesman algorithm. To test this on a piece of paper, before digging under the hood of e.g. pgRouting or OpenTripPlanner, I used a pretend park with trails (in green), with a pretend gridded neighborhood (in pale purple) to select 3 random nodes (numbers) to route through from a given starting point just to see what the outcomes of such an approach might look like.

If you notice, I got confused with the red route in that should have passed through point 9. Here’s my random numbers, 3 random numbers for each route, for a total of 4 required nodes:

  • 11,4,6 — Solid Black Line
  • 7,5,22 — Dashed Black Line
  • 9,2,19 — Solid Red Line

Conceptually, if implemented on the client side this could build loops on any API capable of traveling salesman, given an API wrapper around pgRouting or the addition of traveling salesman routing in OpenTripPlanner, or even using routing from the Google Maps API. Alternatively, the loops could be pre-built on the database side (not randomly, but completely), and then manual or automatic loop prioritization could be implemented to give the series of “best” choices, whether best is determined by miles, terrain, loopyness, trail surface type, mode of travel, etc..

Posted in Recreation, Trail Curation, Trails | Leave a Comment »

What is the center line of a complex polygon? (cont.)

Posted by smathermather on September 26, 2011

If we try to extract the centerline of a polygon using Voronoi polygons, like in my previous post, it works pretty well for hydrologic cases, like extracting a stream centerline from stream banks, e.g.:

Stream/River with digitized banks

Stream/River centerline extracted from stream banks

We’ll use this to extract flow lines, in order to build out a better hydrologic network, but also use it to update property boundaries based on deed descriptions which may alternately follow distances and bearings, or banks and centerlines of streams and rivers.

But, I was still curious to see how well it does on smaller polygons, e.g. does it help with labeling of parcel polygons:

Not perfect, but not bad.   Looks like developing a special case for equilateral triangle, circular, and square shaped polygons (etc) might be in order, as these are probably best labeled in a more simple fashion (see northeast corner of this map, parcel 48517140)… .

Posted in Analysis, GeoServer | Tagged: , , , , | 2 Comments »

Motivations behind Open Source

Posted by smathermather on September 20, 2011

Waxing philosophical tonight.  Apologies in advance.

Paul Ramsey had a great opening keynote opening keynote at FOSS4G on the business model/economics (punchline: business tactic) behind Open Source software, and Free and Open Source companies.  It was funny and convincing, began with absurdity, and made me laugh, as did his PostGIS for Power Users.  His presentation style is at once casual, clever, and passionate.  What caught my attention was the series of slides about the primary and secondary motivators behind making Open Source software: money, community, shared accomplishments, etc.  Is money or should money be the primary motivator behind Open Source software development?  I don’t mean for individual companies– for companies, money may be the primary motivator (if I may divorce individual choices from corporate motivation).  But for individuals working in the Open Source Geospatial community?

If RSAnimate’s video on “The surprising truth about what motivates us

(go ahead, watch it, I’ll wait) is a good indicator of what current research indicates motivates people, money becomes secondary once a certain level of comfort is met, and above that line (whatever that line is) more money actually makes us less productive, more risk averse, and well, less smart, of all things.  So, if Open Source is the superior development model, and we want great Open Source, do we want to be driving the model for Open Source development through the idea that money is the primary motivator for that development?  Money is important, and we want companies to understand that there are business models that include Open Source code as a tactic, but shouldn’t we be articulating carefully who we are and why we have the community, the tribes, of Open Source GeoSpatial developers and users we have?

So those intangibles Paul mentions in his keynote:

  • community
  • shared accomplishments
  • satisfaction of learning and exploring
  • freedom to build
  • membership in a global community

I argue those are the important factors in motivating great FOSS development.  The money.  That pays the bills, feeds the family, keeps the roof over out heads, etc., all vitally important.  But it’s the participation in projects larger and more important than me, the shared accomplishments, the great features and information I can provide to the public, it’s all these things that make this more than a job.  That’s what switches work from vital to integral.  Money can be made in many ways.  Which ways one chooses, that’s what distinguishes jobs from passions.  FOSS is great when it is our passion.

Posted in Conferences, FOSS4G 2011 | Tagged: | 2 Comments »

Copying GWC Directory efficiently– Linux

Posted by smathermather on September 20, 2011

There has been discussion recently amongst some of the web cache builders of switching from file-based tile caching to SQLite or other database driven systems.  I haven’t kept close tabs– perhaps this is already implemented for some.  For GeoWebCache, we’re working with files (lots of them), so copying efficiently if we need to move our cache is important.  The tar command helps here, e.g. (run in GWC cache directory)

 tar cf - * | ( cd /path-to-target-dir/; tar xfp -) 


Posted in GeoWebCache | Tagged: | 2 Comments »

Cleaning PostGIS Geometries — Revised

Posted by smathermather on September 19, 2011

In a previous post:

“Another short post. Got self intersecting geometries? Want to fix them inside PostGIS? Me too. Fortunately, someone has already written the code, so you and I don’t have to:

Now, let’s see how long it takes to run on my 760,000 record landcover table… .”


As usual, there’s a better way.  With PostGIS 2.0, you can (will be able to) use ST_MakeValid.  As a (soon to be) native function, it should be pretty fast.  See Paul Ramsey’s FOSS4G presentation:


Posted in Database, PostGIS, SQL | Tagged: , , , , | Leave a Comment »

What is the center line of a complex polygon?

Posted by smathermather on September 16, 2011

Sat in on a great presentation yesterday by Tim Schaub and Justin Deoliveira on GeoScript. Definitely check out their tutorials. To practice what I learned, I thought I’d apply it to the problem of how to find the centerline of a polygon.

What do I mean by the centerline of a polygon? Well in the case of a stream that is drawn with both it’s banks, the centerline of a polygon is the effective flowline. Also, if you want to label such polygons, it would be useful to be able to calculate this. This could apply to road polygons as well, or labeling complex parcels, etc. etc. At first (and second) blush, there is no trivial solution. However, there are some excellent approximations.

There are some nice articles online about the derivation of centerlines from polygonized roads, e.g. this one. The basic approach is to densify the lines (if necessary), and run a Thiessen (Voronoi) algorithm, then grab the middle line from those polygons. So, let’s start this process, and take it through at least to deriving the Voronoi result using python/GeoScript:

First our stream line:

>>> from geoscript.geom import *
>>> from import *
>>> from geoscript.render import *
>>> poly = Polygon([(2130394.00006841,633268.4901058), ...

Then to view it quickly:

>>> draw(poly, format='mapwindow')

Maybe fly with a little style:

>>> style = Stroke('blue', width=1) + Fill('#0000ff', opacity=1)
>>> draw(poly, style, format='mapwindow')

Ok, now that’s a complicated enough polygon. What do we get from calculating a Voronoi diagram against it?:

>>> polyv=voronoi(poly)
>>> draw([polyv, poly], format='mapwindow')

See the centerline running through the stream? It’s not perfect, but apply some densification before we calculate the polygons, then select only that centerline, and Bob’s your uncle, you have a very nice stream centerline for flowline calculations, labeling, what have you. In future steps, I’ll set this up to extract that line as well, and perhaps host it as a WPS service on GeoServer. If I can (I’m not sure the limitations to GeoScript, have to bug the GeoScript guys today…), I’ll also use it to extend the labeling capabilities for my GeoServer instance without having to dig deep into Java development. Ah, I do love a good API.

Posted in Conferences, FOSS4G 2011, GeoScript, GeoTools | Tagged: , , , , | 8 Comments »

Cleaning PostGIS Geometries

Posted by smathermather on September 1, 2011

Another short post. Got self intersecting geometries? Want to fix them inside PostGIS? Me too. Fortunately, someone has already written the code, so you and I don’t have to:

Now, let’s see how long it takes to run on my 760,000 record landcover table… .

Posted in Database, PostGIS, SQL | Tagged: , , , , | 1 Comment »

Presentation– GeoCamp in Portugal

Posted by smathermather on September 1, 2011

A blog entry so short, it’s practically a microblog:

I’ll be doing a presentation at GeoCamp in Portugal (remotely via skype) on September 24th.

It promises to be an interesting conference.

Posted in Conferences, GeoCamp | Leave a Comment »