Tuesday, January 15, 2013

My comments on the OGC Geopackage Spec


PART A
1. Evaluator:
   Darrell Fuhriman

2. Submission: 
   OGC 12-128r1
   OpenGIS® GeoPackage Implementation Specification

PART B

1. Requirement: Core, #13
2. Implementation Specification Section number: 8.2
3. Criticality: Minor
4. Comments/justifications for changes:

The geopackage_contents table includes four columns used for the bounding box,
but does not specify the units to be used, only the defaults. The spec should
be updated to specifically list the units.

Points for clarification:

1) are the values to always be in lat/long?
 1a) If so, what datum? (Yes, I realized these values are not meant to be
     exact, but it doesn't hurt be clear)
2) are the values to be in the SRID specified in the same row?

If the values are to be specified always in lat/long, then recommend renaming
columns to reflect this:

min_x -> min_long
max_x -> max_long
min_y -> min_lat
max_y -> max_lat

=======================================================================
1. Requirement: N/A
2. Implementation Specification Section number: N/A
3. Criticality: Major
4. Comments/justifications for changes:

I believe there should be an optional extension that allows for the inclusion
of user-defined styling information.

While, I do not believe that the Geopackage format should mandate a specific
styling language, such as SLD or CartoCSS, I do think there should be a standard
location where an application can look for such data. 

The implementation should be highly generic, the intention is to allow
standards to evolve and gain experience before codifying anything, but still
having a single "go to table" for finding styling suggestions.

As an intro suggestion, I imagine there being a table, say "geopackage_styles"
consisting of four columns:

table_name  text NOT NULL
style_name  text NOT NULL
style_version text
style_data text NOT NULL

The primary key would be a composite key consisting of "table_name,
style_name", thus allowing for one table to have multiple styles associated
with in different styling languages.

For example, a table might contain:

| my_table | cartoCSS | NULL  | "some carto css"      |
| my_table | SLD      | 1.1.0 | "<BIG string of XML/>"|

Any styling information included must apply to the named table/view, and only
that table/view. Including styling suggestions for a table/view is purely
optional, and the "geopackage_styles" table need not exist at all.

=======================================================================

1. Requirement: N/A
2. Implementation Specification Section number:9.6
3. Criticality: Major
4. Comments/justifications for changes:

I am concerned that the reference implementation SpatialLite, essentially
mandates the inclusion of the GEOS library. While I have nothing against the
GEOS library, quite the opposite, this presents real problems for people who 
must statically link the libraries, something that is expressly forbidden by
the GEOS Library License (LGPL).

For reference, see: http://blog.burhum.com/post/38236943467/your-lgpl-license-is-completely-destroying-ios-adoption

I strongly encourage the OGC to create a minimal reference implementation,
contains *only* the core requirements, and makes use only of libraries which
can be statically linked.

Tuesday, November 13, 2012

A few things I've been working on


As an update, because you need one once in a while, here are few things I've been up to and/or working on. These are all available on github.


  1. Two gems that work together to add support for PostgreSQL/PostGIS tables as task targets. I also spoke about them at the State of the Map US. There is supposedly video of said presentation online, but I'll be damned if I can find it.
  2. A quick-and-dirty importer script for Census ACS data. 
  3. A series of vector renderings of the bridges of Portland, OR. 
Let me know if you find any of these useful.

Monday, April 9, 2012

Faster Voronoi Diagrams in PostGIS


A couple years back, I posted a quick and dirty function for generating voronoi diagrams in PostGIS. As one of the commenters pointed out, this is not the world's most efficient algorithm. So I started looking into implementing a better one myself, but once again, being a virtuous programmer, I borrowed someone else's code, and modified it to work with PostGIS.

This one's in Python, not PL/pgSQL, so plan appropriately.  It is called similarly to my previous version:

select * from voronoi('table_name', 'geom_column') as (id integer, the_geom geometry);

You no longer need to specify an id column, but the downside is that there's no longer a relationship between the id of the input point, and the id of the output polygon. On the other hand, it's much, much, much more efficient. At least a couple orders of magnitude. In testing, my 40,000 points of input only took 20 seconds to calculate, whereas previously it took... well, I don't know, because I didn't want to wait that long.

Code is here: http://db.tt/xen7XHwC  No guarantees it actually does anything correctly, but my limited testing seems to work. Enjoy.

UPDATE: the code linked above only works with Python 2.x. If you look through the comments, you'll see there's a link to a version of my code for 3.x, but it still has a couple of bugs which I have not had time to investigate.

UPDATE 2: See the comments below about the QGIS code also producing incorrect output with this function. I'll try to investigate in my copious free time.

UPDATE 3: Matthias has published a version that corrects the problems in my initial code. His dropbox link is here: http://db.tt/gwEGpu0Y.  I've also published it as GIST, here: https://gist.github.com/darrell/6056046


Tuesday, August 16, 2011

This is such great news, it deserves a post of its own. The Sextante Blog has released a video showing Sextante integration with ArcGIS. While I haven't seen the full list of tools, I've every reason to think it will include all the Sextante tools, which would for many people obviate the need for an ArcInfo ArcGIS for Desktop Advanced license, as well as Spatial Analyst, Geostatistical Analyst, and maybe others...

Tremendous news, indeed.

Thursday, July 14, 2011

Ten years is both a long time, and a short time...

My friend Brandon, the Mercatorial Librarian[1]  has a post up reminding me that it's been ten years since we went to Nigeria to install computer labs and do training for professors in the Library Science department at Bayero University Kano in Kano, Nigeria.

It was that event which led me to Child Aid and doing similar work at Probigua in Antigua, Guatemala in 2005. All of which ultimately led to my Master's Thesis research on the political ecology of donated computers and e-waste in Accra, Ghana[2]. One of these days I'll really get that research published (I keep telling myself).

Anyway, it just reminds me that when I'm geeking out on this blog, or teaching about spatial databases (this fall at Portland State, GEOG 4/575, come on over), where my true passion lies.


[1] I assume this is a reference to Mercator, so how can I not like it?
[2] How many Geographers actually get scooped by National Geographic? Well, this one does. Turns out I was there at the same time as the NG guys, though they published first, obviously.

Tuesday, April 19, 2011

Geekery on display

The proposal that Sarah Beecroft and I wrote for the Open Source Bridge 2011 conference was accepted, as was our proposal for the Open Source GIS Desktop Smackdown, which we gave at GIS in Action (see previous post). I guess I have to post one of these badges now:

Wednesday, March 30, 2011

Recent goings on

Been a bit infrequent on updates, but I'm going to work on that.

Yesterday I presented at the "Open Source GIS Desktop Smackdown" as part of the GIS in Action regional conference. We presented gvSIG, OpenJUMP, and Quantum GIS. I presented gvSIG (using the OA edition), and  handily trounced the competition, largely, I think based on the modeler, and the fact that gvSIG has a number of advanced features, in particular more advanced topology tools than anything I've seen outside of Arc. Now if only the Mac interface worked better.

Locally, the PDX OSGeo group I'm part of has officially become an OSGeo chapter, which comes with, well, very little really, but I think it's important to recognize the good work that OSGeo is doing.

Oh, and finally, as part of the aforementioned GIS in Action conference, we're running an unconference tomorrow (March 31st) and a hackathon on the following day (April 1). It's not too late to sign up and attend - and it's free! More info and registration here: http://calagator.org/events/1250459876.

Hopefully future posts will have more technical content, but for now, that is all.

Monday, September 20, 2010

Voronoi Diagrams in PostGIS

(Update: A faster version of this code is here: Faster Voronoi Diagrams in PostGIS)

I found myself in a situation where I needed to create a Voronoi diagram from a set of points using PostGIS. This isn't built in, but a little googling turned up a function written by Mike Leahy. I adapted it and made it a bit more generic, so it shouldn't require any editing to make it work for many (most?) cases.

Call it as: select * from voronoi(table_name text,table_primary_key text,geom_col text)  as (id id_type, the_geom geometry)


For example:



select * from voronoi('oregon_cities', 'id', 'the_geom_centroids') as (id integer, the_geom geometry);


The 'as' clause is required because we don't know and don't want to assume what type your primary key might be. But, because we're returning a record type, the query planner wants to know what type to expect. If you're always using the same type, say an integer for your primary key, then it would be easy to define a type thusly:


create type my_type as (id integer, the_geom geometry);


Then change the code at line 24 from 'rec record;' to 'rec record%my_type;' and you will no longer need the 'as' clause.


Code at this URL: http://db.tt/aInuiJ2.  Enjoy.





Sunday, April 4, 2010

Pondering vector representations.

So one thing I've wondered is why more GIS systems can't/don't use B-splines, opting instead for simple lines. The OGC Simple Features standard defines a Curve, which must specify its method of interpolation between points, but then only defines one method – straight linear interpolation.

Obviously there are disadvantages to using b-splines, such as the assumption of accuracy which permeates so many people's interactions with GIS data. At least when you using simple linear features, as you move to a large scale map, you can see the clumsy straight lines that make up your data. But it sure would look nicer when outputting the same data to use B-splines.

Not being hugely math skilled anymore (woe for math atrophy), I'm not even sure how to go about answering the question. But some of the more interesting issues that bounce around in my mind are:

1) Do B-splines/bezíer curves even work in non-euclidean (in particular spherical) geometry?
1a) If they do, then how would one go about projecting them into a euclidean space – if one can meaningfully do so at all?
2) Assuming a "bezíer polygon" were defined as closed series of curves just like linear polygons, how would one calculate the area of said polygon?

Any math über-geeks out there in my vast (hah!) readership have any insights?

Wednesday, November 25, 2009

Too much of a good thing?

Slashgeo reports yet another new Open Source GIS tool, noting "Open source GIS software is crowded with options: QGIS, uDig, gvSIG, OpenJUMP, MapWindow, GRASS, OSSIM, etc."

Yes, it is - and the question to me is: "Why so many?" - I understand the arguments for a diverse software ecosystem, and I even agree with them. But with the possible exception of GRASS, most of these packages implement the same basic functionality without implementing the advanced functionality that is necessary to seriously take on ESRI. Plus, the UIs are almost always terrible, which makes the problem even worse.

So, in that spirit I'm listing a few things that I think are missing from most, if not all, OS GIS software, in no particular order:

1. Topological data model (the only exception I can think of is GRASS)
2. Editing, especially centralized, version controlled editing.
2a. Which means you need a topology model in your database
3. UIs not designed by software engineers. (Well, at least ESRI has this problem, too.)
4. Quality cartographic tools.
5. COGO tools
6. Metadata editing tools
7. Scriptability (GRASS, being command-line based is fairly scriptable, I know of no others that are.)
8. Runs on my Macs.
9. Comprehensive interface for building extensions

Well, those are a few that come to mind right away. Make more suggestions - maybe we can turn this into a manifesto.

Monday, November 23, 2009

Open Publishing & Cartography 2.0

The new issue of Cartographic Perspectives is available for free as part of a test of going all digital and open-access. Three Cheers for NACIS on that one, let's hope they keep it up.  The lead article is by David DiBiase and makes the case for more open access. David and I organized a session at the AAG Annual Meeting in 2007 on "Envisioning a post-proprietary Geography" – sadly we were somewhat poorly attended, no doubt in part because of the free wine being given away by publishers at the same time. (The more conspiratorially minded among us might think that a bit *too* coincidental...)

The issue also features the introduction by some of my former classmates (go Anthony), of the Cartography 2.0 website – an online source book for dynamic mapping.

You guys are embarrassing me with all the awesomeness. Keep it up - time for me to get working, too.

Wednesday, November 4, 2009

Announcing: PDXBikemap


I'm pleased to announce the first public release of pdxbikemap.org -- it's a street routing tool for finding optimal paths while on your bike, where optimal is defined as "balancing speed and safety."

The application is still very much in beta, but please report any issues you run into, and especially send suggestions. But before you do, check out the FAQ and the known issues.

Enjoy!

Wednesday, October 21, 2009

Planet Money blows it

The most recent episode of Planet Money talked to an American oil worker in Angola and an Angolan about the differing ways of experiencing their country. This is a noble thing, indeed and I have no complaints about it – in theory. But I think they really dropped the ball this time.

In particular, there was a discussion about the Chinese government hiring Chinese laborers to build Angolan infrastructure as part of deal to guarantee oil prices to China, but they missed the obvious question: how many Angolans does the oil company hire vs. foreigners? Who's getting the $20,000/mo rent for the American's apartment?

But the thing that surprised me most was the way in which they seemed surprised at what the Chinese were doing.  This sort of thing has been SOP for aid-giving countries for decades (though they don't usually send labor). I once met a woman at dinner party who worked for a company that existed only because of aid tying. (The company made very large pipes for use in water/sewer systems), a friend of grew up in Egypt because his parents sold American farm-equipment around North Africa.  Obviously American farm-equipment is of high quality, but nonetheless, the people were "buying" it with American aid money and had no choice but to buy from an American manufacturer.

Similarly, the oil for infrastructure deal is as old as colonialism – think of the Reuters Concession in Iran in the late 1900s, or any number of "concessions" that were forced upon the decaying Ottoman empire in the 19th century. Similar arrangements were widely made in Africa. Chances are our American oil worker is working for a company with quite similar "arrangements".

In general, I think Planet Money has been fantastic at exploring economic issues (albeit with something of a tendency to gloss over or ignore serious critiques of the statements given by their various interviewees), but so far their work on the economics of development has really been lacking.

Come to think of it, I think maybe their thinking is just too narrow - much like economics in general, they try to oversimplify the world to fit into economistic models rather than looking at the societies and politics that economics is operating in. Like many economists they forget that economics is not physics - it's not something that operates independently of human beings. It is a creation of human beings – something we should always be careful to remember. This, of course, was so elegantly argued by Karl Polanyi decades ago, but is so easily forgotten.

Here's hoping that in the future they take a bit more care in how they report and who they choose to discuss development economics. I'd love to see them get someone like Ha-Joon Chang – but that might be hoping for too much.

Anyhow..

Monday, October 5, 2009

Buffering only the upslope areas of a DEM

OK, here's the solution to the problem proposed in my previous post.  It's not a perfect solution, as it doesn't account for all possible types of terrain (more on that below), but it's pretty close and in the data I have, works pretty well.

The first thing to do is take care of the slope and the 10' elevation change in one swoop. By adjusting the size of our pixels, we can make sure that any change in the slope that meets the 40% rule also meets the elevation change. In other words, what is the minimum Δx (i.e. the resolution) that yields a change of Δy>=10' at an angle θ?


  • Because: y=x·sin(θ)
  • We substitute: 10= x·sin(tan-1(.4))
  • Solving for x yields x=26.9. We round that to 27 for convenience.

  • Now calculate your slope raster with an output resolution of 27ft (or equivalent, depending on your projection).
  • Reclass that raster so that everything < 40% is null.
  • Using your >=40% layer assign a value to each grouping (in GRASS, this is r.clump; in Arc*, this is the Region Group tool from Spatial Analyst).
This next part is hard because looping pretty much requires a programming language - I used GRASS (wrapped in a shell script), you could use AML or Python if you're an ESRI user.


For each group:
  • Find minimum elevation in that group
  • Buffer out 300' from the group
  • Delete all pixels from the buffered region where slope is null and elevation is less than the minimum for that group.
Ta da!  You have a raster buffered out 300' upslope.

But wait....


What if a pixel is both downslope from one face and upslope from another? (Imagine a ledge or an old lake shoreline like the bench in northern Utah created by Lake Bonneville.)  Well, in this case, we will have eliminated those pixels, which we don't want to do.

We can solve this by taking an intermediary step - creating an empty raster, then instead of deleting the pixels, do a logical OR against the output of the previous iteration of our loop. This allows us to keep our pixels if they're within 300' of any upslope region.

Unfortunately, that loop can add some significant processing time, anyone have another way to do it?

Thursday, October 1, 2009

Interesting challenge

Given that lately I've been doing a lot of ETL, which involves working with a lot of low-level data structures and data transformation, I don't get much chance to think about some interesting analysis problems, particularly raster based ones. But today, I got presented with one.

Using a DEM, create a 300' buffer around any slope greater than 40%, where the change in elevation from one edge of the slope to another is at least 10', but buffer only on the upslope side.

How would you do it?  I'll post my own answer soon.

Saturday, September 26, 2009

Tweaking OpenLayers WFS requests to work with featureid

OpenLayers (at least as of 2.8) WFS requests always include the bbox, but that doesn't work if you specify a featureid (the two are defined as mutually exclusive).  Here's a quick work-around for this problem using apache's mod_rewrite.

I'm using apache as an AJP proxy in front of geoserver, but there's no reason this wouldn't work with other WFS servers like mapserver, etc. Put this in the appropriate config file:

RewriteEngine On

RewriteCond %{QUERY_STRING} featureid=[^&]+ [NC]
RewriteCond %{QUERY_STRING} (.*)bbox=[^&]+(.*) [NC]
RewriteRule (.*)  $1?%1%2 [P,L]

ProxyPass /geoserver/ ajp://localhost:8009/geoserver/

Tuesday, September 8, 2009

Introducing....

In what may be a fit of foolishness, I thought I'd create this blog to post things that I find useful in my day-to-day work, coupled with the occasional random thoughts on a topic of interest, usually related to the world as I see it (however skewed that may be).

Expect to see stuff on Economic Development, Programming, and GIS work -- especially if it's related to open source GIS.