Building Utilities.


The GISToolkit is above all else a Toolkit, it contains features and facilities that make it easier to manipulate geographic data.  If you are building a utility, perhaps the javadoc would be a good reference.  Following is an example of a utility you could build with the GISToolkit.

Read Data from a shape file, and upload it to a PostGresDatasource.

Steps needed.
1. create the data source for the source data
2. create the data source for the destination data
3. loop through 1 and write it to 2.

A code example follows.

// construct the datasource for the source data
ShapeFileReader tempReader = new ShapeFileReader(tempShapeFile.getAbsolutePath());
Record tempRecord = tempReader.read();

// construct the data source for the destination data                           
UpdateablePostGISDataSource tempDBDatasource = new UpdateablePostGISDataSource();
tempDBDatasource.setDatabaseName(getDatabaseName());
tempDBDatasource.setDatabasePassword(getDatabasePassword());
tempDBDatasource.setDatabasePort(getDatabasePort());
tempDBDatasource.setDatabaseServername(inConnect.getDatabaseServername());
tempDBDatasource.setDatabaseURLBase(inConnect.getDatabaseURLBase());
tempDBDatasource.setDatabaseUsername(inConnect.getDatabaseUsername());
tempDBDatasource.setDatabaseShapeColumn("Shape");
tempDBDatasource.setDatabaseSpatialReferenceID(1);
tempDBDatasource.setDatabaseTableName(tempTableName);
 tempDBDatasource.connect();

// loop through the source datasource inserting the records into the destination data source.
int tempCommit = 1;
while (tempRecord != null){
      tempCommit++;
      if (tempCommit % 100 == 0){ // commit every 100 records
           tempDBDatasource.commit();
      }
      tempDBDatasource.insert(tempRecord);
      tempRecord = tempReader.read();
}
tempDBDatasource.commit();                      

Many manipulations of the record can be done in the interrum, changing of attribute data, based on criteria.  Modification of shape s.
If the projection is to be changed, then give the source datasource a projection, and it will project the record to that projection so it will be in a different projection in PostGIS.