Pages

Monday, 7 September 2009

Taking Boiler Plate out of Examples

I was reviewing the GeoTools example code today with Michael Bedward - preparing for an a tutorial at FOSS4G this year.

One of the things that always comes up in example code; is the requirement to "show" the result. As a result a the majority of our example code was actually examples of how create quick and dirty swing user interfaces.

So our day was spent stripping out boilerplate user interface code to a jar appropriately tilted "gt-swing" so that examples can stay focused on being examples.

Here is a small example of a wizard page for connecting to a shape file:


Here is before:


File file;


JFileChooser chooser = new JFileChooser();

chooser.setDialogTitle("Open Shapefile for Reprojection");

chooser.setFileFilter(new FileFilter() {

public boolean accept(File f) {

return f.isDirectory() || f.getPath().endsWith("shp")

|| f.getPath().endsWith("SHP");

}

public String getDescription() {

return "Shapefiles";

}

});

int returnVal = chooser.showOpenDialog(null);

if (returnVal != JFileChooser.APPROVE_OPTION) {

System.exit(0);

}

file = chooser.getSelectedFile();


And here is after:


File file = JFileDataStoreChooser.showOpenFile("shp", parent );


The other thing that has happened in cleaning up examples is a real focus on the style interfaces. Specifically going through and making sure all the new concepts introduced are accessible, and ensuring that deprecated methods are not used in example code.

Documentation harmed in the making of todays blog:

Thursday, 13 August 2009

PostGIS OSX

The PostGIS experience on mac is a very slick and slippery slope.

First of all the Installers are very Slick

There are a series of nice mac installers that have been bundled up by William Kyngesburye.

And the installers are very good about beeping at you and asking you to install GDAL and PROJ prior to postgis.

And then the slippery ...

The installer don't provide much guidance on where things went ... I am used to having a postgis_template created for me by the windows installers. And all my notes are based on creating new database using that as a safe starting place.

Here were the steps needed to create my own postgis_template:
1) cd /usr/local/pgsql/bin (and then use ./ to get it to pick up the commands)
2) ./createlang plpgsql template_postgis -U postgres
3) ./psql -U postgres -f /usr/local/pgsql/share/lwpostgis.sql template_postgis
4) ./psql -U postgres -f /usr/local/pgsql/share/spatial_ref_sys.sql template_postgis

Other then that pgAdmin looks quite happy.