my.swa's development blog

Subscribe to RSS feed

Google Earth command line options

It seems that Google doesn't want to tell possible command line options to linux users. That's why I started to collect them here:

Open a KML file:
googleearth /home/myswa/GPS/mytracks/tracks.kml

Be careful, you have to indicate the absolute file path. The command will not work with a relative path. (Is there any Google developer who uses linux?? I suppose NOT!).

With the following shell command, you can open all KML files from one directory:
googleearth `find /home/myswa/GPS/mytracks/ | grep ".kml$"`

Change the Qt style:
googleearth -style <style>

If there are other options, please let me know!

Open all .shp files from one directory

If you have several Shapefiles in one directory and you want to open them at once in QGIS, try this command:
qgis `ls | grep ".shp$"`

Connect to PostgreSQL / PostGIS from OpenOffice 2.4

,

The open source office suite OpenOffice.org provides the possibility to connect to PostgreSQL / PostGIS databases as well as to MySQL, Oracle et cetera.
Before starting the package named openoffice.org-sdbc-postgresql has to be installed. Then try the following steps (I did it with version 2.4): Choose "Connect to an existing database" and then the appropriate driver "postgresql". In the next step enter the database connection properties (actually this was the only tricky part because the correct syntax was untracable). Without trying it, I suppose that localhost works as well.
host=www.yourhost.net port=5432 dbname=yourdb
Finally enter your user name. That's it!

Conversion from TIFF-file with world file to GeoTIFF using gdal

Sometimes you have a TIFF-file which you've georeferenced with a world file but you need a GeoTIFF-file. Then try the following gimmick using gdal.

gdalwarp -s_srs "EPSG:4326" -t_srs "EPSG:4326"
s_27e_16s.tif ../geotiff/s_27e_16s.tif

The gdalwarp utility is normally used to project images, so the crucial point is that you have to set the source projection as well as the destination projection although they are the same.

Intersection function implemented in GeoTools 2.4

,

GeoTools is an open source (LGPL) Java code library which provides standards compliant methods for the manipulation of geospatial data. Unfortunately the GeoTools page and its documentation is not really clearly arranged.

Here is the way I implemented a quite common intersection analysis with the GeoTools library version 2.4.

First create a new data store:
public void setDataStore(Map connect) {
  try {
    this.dataStore = DataStoreFinder.getDataStore(connect);
  } catch (IOException ex) {
    System.err.println("DataStore not found");
  }
}

Variable connect contains the connection parameters, if a shape file is on hand, it looks like this:
File file = new File("/path/to/shape/file");
HashMap connect = new HashMap();  
connect.put("url", file.toURI().toURL());

If a PostGIS database is connected, variable connect looks like this:
Map connect = new HashMap();
connect.put( PostgisDataStoreFactory.DBTYPE.key, "postgis" );
connect.put( PostgisDataStoreFactory.HOST.key, "www.yourserver.net" );
connect.put( PostgisDataStoreFactory.PORT.key, "5432" );
connect.put( PostgisDataStoreFactory.DATABASE.key, "database" );
connect.put( PostgisDataStoreFactory.USER.key, "username" );
connect.put( PostgisDataStoreFactory.PASSWD.key, "password" );

Once the data store is created, a new bounding box filter is initiated. Basically there are several ways to create such a filter, this is only one possibility.
String cqlExpression = "BBOX("
                    + geometryColumnName
                    + ","
                    + minX
                    + ","
                    + minY
                    + ","
                    + maxX
                    + ","
                    + maxY
                    + ",'EPSG:4326')";
Filter filter = CQL.toFilter(cqlExpression);

With this filter the geometries which intersect the defined bounding box are selected.
(Note that the selected geometries are not clipped.)
FeatureCollection featureCollection = featureSource.getFeatures(filter);
FeatureIterator featureIterator = featureCollection.features();

Before the geometries are clipped a new polygon which represents the bounding box has to be created.
//Instantiate the geometry factory
GeometryFactory geometryFactory =
  new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING), 4326);
//Create the bounding box polygon
Coordinate[] bbox = new Coordinate[5];
bbox[0] = new Coordinate(minX,minY);
bbox[1] = new Coordinate(minX,maxY);
bbox[2] = new Coordinate(maxX,maxY);
bbox[3] = new Coordinate(maxX,minY);
bbox[4] = new Coordinate(minX,minY);
LinearRing bboxRing = geometryFactory.createLinearRing(bbox);
Polygon bboxPolygon = geometryFactory.createPolygon(bboxRing, null);

Now we iterate through the selected geometries and clip them
//Iterate over all features
while( featureIterator.hasNext() ) {
  Feature feature = featureIterator.next();
  Geometry geometry = feature.getDefaultGeometry();
  //Clip the geometry and write the intersected geometry
  writeGeometry(writer, geometry.intersection(bboxPolygon));
}

Last but not least all needed packages have to be added to the classpath and imported.

PostGIS: How to use native PostGIS functions in QGIS

, ,

Provided that you know how to query a PostGIS database, you can use native PostGIS functions in QGIS in the following manner:

Let's assume you want to display all villages that lies within a certain distance from the main road. Of course you would use a buffer query.

Choose "Add a PostGIS Layer", the following dialog opens:



Select the corresponding table and double-click it. The PostgreSQL Query Builder dialog opens:



At the bottom there is the "SQL where clause" panel, where you can enter the required query. In our case the where clause looks like this:
ST_WITHIN(the_geom_wgs84, (SELECT ST_BUFFER(the_geom_wgs84, 0.01) FROM roads_gen WHERE surface = 2101 LIMIT 1))

To control the result I added the main roads and all other villages to the project. This is the result:

The yellow dots are the selected villages from the buffer query, the violet dots are all villages and the line represents the road.

MapServer: GetStyles request

,

MapServer provides the possibility to request a valid Styled Layer Descriptor (SLD) file from a map file.
At least the following parameters are necessary for a valid request:
request: is 'GetStyles'
map: path to the map file
version: the current WMS version
layers: the SLD file of these layers is sent back, it is possible to request any number of layers

For further information see also http://mapserver.gis.umn.edu/docs/howto/sldhowto

PostGIS / PostgreSQL: JDBC Driver for Java

,

JDBC drivers for PostgreSQL database:
http://jdbc.postgresql.org/download.html

Use the JDBC 3 driver, if you compile against Java 1.5.0 (at the moment still necessary for Mac OS).

JDBC driver for PostGIS: http://postgis.refractions.net/download/

To see how you can establish a new connection to a PostGIS data base, go to the PostGIS documentation: http://postgis.refractions.net/documentation/manual-1.3/ch04.html#id2539154

PostGIS: Update geometry_columns table

,

If you add or remove tables with geometry columns, the geometry_columns table isn't updated automatically. To update the geometry_columns table try:
SELECT probe_geometry_columns();

Usage of proj.4

Some examples of usage of proj.4

Transversal equal-area azimuthal Hammer projection with scale 1:55000000 and k = sqrt(2), m = 1 and n = 0.5
proj +proj=hammer +lon_0=18.5dE +x_0=0.239690
+y_0=0.151561 -m 1:55000000
February 2012
M T W T F S S
January 2012March 2012
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29