Smathermather's Weblog

Remote Sensing, GIS, Ecology, and Oddball Techniques

Archive for October, 2011

PostGIS 2.0SVN and Raster

Posted by smathermather on October 28, 2011

Got PostGIS 2.0 installed on a Debian machine, with Raster enabled, and put my first image in thanks to the directions in PostGIS In Action. Here’s the auto-generated SQL in pgAdmin:

  rid serial NOT NULL,
  rast raster,
  CONSTRAINT ldi_10ft_pkey PRIMARY KEY ( rid ),
  CONSTRAINT enforce_srid_rast CHECK (st_srid( rast ) = 3734)

CREATE INDEX ldi_10ft_rast_gis_idx
  ON ldi_10ft
  USING gist
  (st_convexhull(rast) );

Now for some rastery fun.

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

PostgreSQL dump for PostGIS upgrade

Posted by smathermather on October 27, 2011

I’m working through the Hard Upgrade instructions for PostGIS 2.0SVN install instructions. No great surprises, but a succinct set of steps for trying out PostGIS 2.0 early.

In our case, we needed to exclude larger (30GB) tables from the dump needed to do an upgrade– we’ll build those into the new database selectively. Looking to the pg_dump instructions, the dash “T” (-T) flag is what we need. Word to the wise (or note to self, as it were)– explicitly calling out the schema name in the table wildcard helps.

pg_dump -h localhost -p 5432 -U postgres -Fc -b -v -T cool_schma.*contou
rs* -f "cool_database.backup" CM

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

Postgis for breakfast: ST_Donut — Revision

Posted by smathermather on October 27, 2011

A commenter on my last ST_Donut post pointed out that we were essentially using not one but two buffers and and ST_Intersection to test where a point lay.  Bad Spatial SQL. Very bad Spatial SQL. Actually, at Paul Ramsey’s PostGIS for Power Users presentation at FOSS4G this year, I think he mentioned not doing that very thing, and I chuckled to myself, “Well, even I know better than that.” So much for false pride.

So here’s the revision, adapted as before from Sorokine:

Revised Oct 28th

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

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

Posted by smathermather on October 18, 2011

Just a quick post on this one, this time. I haven’t implemented an approximation of Bálint MiklósScale Axis Transform in PostGIS yet, and I don’t think I’ll dare try in GeoTools for GeoServer just yet, but I thought I’d give a preview of the sensitivity of the medial axis calculations in “bumpy” streams with the following image:

Medial axis of

As you can see, the problem isn’t restricted to giraffes… 🙂 .

Posted in Analysis, GeoServer, PostGIS | Tagged: , , , , , , | Leave a Comment »

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

Posted by smathermather on October 8, 2011

I glossed over the difficulties of finding the centerline of a complex polygon in the last couple of posts, and didn’t realize the disservice until we got to the nitty-gritty of finding the centerline of “bumpy” streams, for which our solution, which is arguably a discretized version of the traditional medial axis, is quite sensitive to noise and “bumpiness”.

With a little more googling, my collegue T. Kraft found Bálint Miklós site describing The Scale Axis Transform, an alternate technique that is not sensitive to noise, but looks at the importance factor of a feature to control whether we show an axis for it, e.g.:

Notice how many “extra” lines we have in the initial medial axis? The scale axis transform really helps in trimming these out. There are some really well done videos describing this process conceptually for both the 2D case and the 3D case.

We’ll see if we can implement an approximation of this technique in PostGIS.

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

Postgis for breakfast: ST_Donut

Posted by smathermather on October 6, 2011

This post typed into my iPod as an homage. Assisted today by my collegue, J. Stein.

Moderate obfuscation of locations is an important technique for the protection of data, say something sensitive like the nesting locations of the very rare and strange fuzzy-bellied gnat catcher. We still want to display the data, but want to make it slightly wrong.

A naive approach would place it a random distance away, i.e. Location +- random()*500ft. Unfortunately, this could be a distance as small as 0 ft away, not an outcome we want.

So, instead we constrain our placement of random points to a minimum and maximum distance away. Enter ST_Donut. We need to construct a donut, and then place a random, ahem, sprinkle on it, and return a point:

  geom Geometry, dough numeric, nut numeric, geom2 Geometry 
 RETURNS Geometry
 AS $$

  donut Geometry;
  donut = ST_SetSRID(ST_Difference(ST_Difference(ST_Buffer(geom, dough), ST_Buffer(geom, nut)), ST_SRID(geom)),geom2);

RETURN donut;

$$ LANGUAGE plpgsql;


Thanks to sorokine:

 CREATE OR REPLACE FUNCTION RandomPoint ( geom Geometry ) RETURNS Geometry AS $$ DECLARE maxiter INTEGER := 1000; i INTEGER := 0; x0 DOUBLE PRECISION; dx DOUBLE PRECISION; y0 DOUBLE PRECISION; dy DOUBLE PRECISION; xp DOUBLE PRECISION; yp DOUBLE PRECISION; rpoint Geometry; BEGIN -- find envelope x0 = ST_XMin(geom); dx = (ST_XMax(geom) - x0); y0 = ST_YMin(geom); dy = (ST_YMax(geom) - y0); WHILE i maxiter THEN RAISE NOTICE 'number of interations exceeded max'; END IF; RETURN rpoint; END; $$ LANGUAGE plpgsql; 

Mmmm, donut…

Edit: October 8, 11:06

The real function is:

  geom Geometry, dough numeric, nut numeric, geom2 Geometry
 RETURNS Geometry
 AS $$

  donut Geometry;

  donut = ST_SetSRID(ST_Difference(ST_Buffer(geom, dough), ST_Buffer(geom, nut)), ST_SRID(geom));

The code I had in the block at the top is the overloaded version. In this case it can take in two geometries; the second geometry is a limiting geometry– say a boundary outside of which you don’t want to place the randomized point. PostgreSQL let’s you overload functions, so if two functions have the same name, but different variable input, whether by type or number or both, it will run the function that matches the name and inputs. This allows us to create two functions with the same name, but slightly different purposes. BTW, this overdetermined function should probably check to see if the second geometry is a polygon, but it does not. Buyer beware… .

Posted in Analysis, Database, Ecology, PostGIS, Security, SQL | Tagged: , , , , | 3 Comments »

OGC Web Services and Security

Posted by smathermather on October 5, 2011

I’ve been starting to inform myself on authentication/authorization schemes for OGC Web Services (OWS). This is because, while I’m pretty pleased with most of the functionality basic mapping of our internal GeoExt/GeoServer/PostGIS stack, user editing is the next natural step. As it is now, users can access a variety of really detailed useful layers, print to PDF, and for the most part the interface is simple and intuitive. The cartography is looking pretty good too. Some additional thought might be put into controlling which layers are available with other layers to ensure great cartographic output at all times, but baring some additional event handlers, and thus a much better JavaScript writer than I am, this won’t happen soon.

So, I turn my attention to markup and layer editing. Authentication and authorization must precede this. In my searches, I found this summary document from CamptoCamp from FOSS4G 2011 2010, with some great schema on the different options. The basic breakdown as I read it is this: there are two categories of protection: integrated authentication, such as the GeoServer Security Subsystem, and proxied authentication, such as 52˚ North WSS, SecureOWS, or GeoShield. The proxied systems can be further subdivided into systems which create an https tunnel with separate client and server software to provide a decoding localhost to prevent packet sniffing (i.e. SecureOWS), a web security service (WSS) service layer (i.e. 52˚ North WSS), and GeoShield– which can either act as a proxy or a (soon to be released) plugin for GeoServer’s existing subsystem (if I understand things correctly– which by things I mean this document from FOSS4G 2011, as I missed the presentation itself).

The nice part for SecureOWS, as I see it, is that it creates a tunneled connection, so if you’re interested in preventing sniffing, man-in-the-middle attacks, etc., the extra complication of running a localhost decoder for SecureOWS might be worth it.  It’s a minor complication, but it is not as simple as HTTP BASIC authentication, which is what e.g. the GeoServer security sub-system does.  SecureOWS also should work with any client software that can access OWS services.  What I like about GeoShield is the ability to use Common Query Language (CQL) (and hopefully ECQL) to constrain almost every bit of behavior, from the extent returned, to the styles available, etc. etc., all that using a language construct common to GeoServer users, in addition to service level stuff like GetFeatureInfo, etc..  And finally, it seems that 52˚ North WSS (or WSS setups in general) are meant to handle end to end security, including encryption.  I don’t know if this level of complexity constrains potential client software, but it seems like it could.  This point might be moot, if the objective is to use a modern browser as the client, but could matter with legacy desktop applications (I’m now into the territory of suppositions and guesses, so please correct me if I’m wrong).  That said 52˚ North WSS also has fine control over geographic extent, service level, layers, etc., much as GeoShield.

What’s my conclusion?  I wish I knew.  I’m going to have to do some yak shaving tests.  GeoShield passed initial tests.  It seems, so far, to be easy to set up and maintain, and the Ext “Desktop” look and feel is downright cute.  GeoServer’s subsystem can authenticate against other services, such as LDAP, so I’ll be playing with that too.  We’ll see how far I get from there, and whether I test the encrypted options (SecureOWS and 52˚ North WSS) to ensure end-to-end security as well.

Posted in GeoServer, Other, Security | Tagged: , , | 4 Comments »

Strange Maps

Posted by smathermather on October 2, 2011

I was nearing e-mail bankruptcy; instead of declaring it, I organized, and sorted through the last three years of e-mails. I found a great e-mail from a friend and fellow geographer from undergraduate who sent me a link to Strange Maps. Re-posted here for your pleasure, if you haven’t stumbled upon this already:

Thanks Ms. Armstrong.

Posted in Other | Tagged: , , | Leave a Comment »

Redirect tomcat ROOT

Posted by smathermather on October 1, 2011

A quick post today:

If you’re running Tomcat, the root of your application container will look something like this:

That’s not what I want my users to see at root.  I want them to see my application.  So I borrowed some instructions from this blog to make that root directory point elsewhere.

Of course, you could do this with a proxy service too, a redirect with an Apache instance in front, etc. etc. And there may be subtler ways to get the job done even within Tomcat, but it does that– it gets the job done.

Posted in Other | Tagged: , , | Leave a Comment »