Skip to content

lonnyj/geodb

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introducing GeoDB

GeoDB is a spatial extension of H2 and Apache Derby, two Java SQL databases. GeoDB utilizes the JTS library as its geometry engine and the Hatbox library for spatial indexing support.

Quickstart

H2

  • Download GeoDB

  • Unzip the geodb-0.8-app.zip file

  • Update the PATH environment variable to include geodb-0.8/bin

  • Run the geodb command:

      % geodb foo
    
  • Initialize the spatial database:

      @h2> CREATE ALIAS InitGeoDB for "geodb.GeoDB.InitGeoDB";
      @h2> CALL InitGeoDB();
    
  • Create a spatial table:

      @h2> CREATE TABLE spatial (id INT AUTO_INCREMENT PRIMARY KEY, geom BLOB);
    
  • Create some spatial data:

      @h2> INSERT INTO spatial (geom) VALUES (ST_GeomFromText('POINT(-5 -5)', 4326));
      @h2> INSERT INTO spatial (geom) VALUES (ST_GeomFromText('POINT(0 0)', 4326));
      @h2> INSERT INTO spatial (geom) VALUES (ST_GeomFromText('POINT(5 5)', 4326));
      
      @h2> SELECT ST_AsText(ST_Buffer(geom, 10)) as buffer FROM spatial;
    
  • Create a spatial index

      @h2> CALL CreateSpatialIndex(null, 'SPATIAL', 'GEOM', '4326');
    
  • Perform a spatial query

      @h2> SELECT ST_AsText(geom) FROM spatial WHERE id IN (SELECT CAST(HATBOX_JOIN_ID AS INT) FROM HATBOX_MBR_INTERSECTS_ENV('PUBLIC', 'SPATIAL', -2, 2, -2, 2));
    

Apache Derby

  • Download GeoDB, Hatbox and JTS

  • Update the CLASSPATH environment variable to include the three jar files

  • Download Apache Derby 10.10.1.1 or newer

  • Unzip the db-derby-10.10.1.1-bin.zip file

  • Update the PATH environment variable to include db-derby-10.10.1.1-bin/bin

  • Run the ij command:

      ij> connect 'jdbc:derby:foo;create=true';
    
  • Initialize the spatial database:

      ij> CREATE PROCEDURE InitGeoDB () language java external name 'geodb.GeoDB.InitGeoDBProc' parameter style java modifies sql data;
      ij> CALL InitGeoDB();
    
  • Create a spatial table:

      ij> CREATE TABLE spatial (id INT NOT NULL GENERATED ALWAYS AS IDENTITY CONSTRAINT spatial_pk PRIMARY KEY, geom VARCHAR(32672) FOR BIT DATA);
    
  • Create some spatial data:

      ij> INSERT INTO spatial (geom) VALUES (ST_GeomFromText('POINT(-5 -5)', 4326));
      ij> INSERT INTO spatial (geom) VALUES (ST_GeomFromText('POINT(0 0)', 4326));
      ij> INSERT INTO spatial (geom) VALUES (ST_GeomFromText('POINT(5 5)', 4326));
      
      ij> SELECT ST_AsText(ST_Buffer(geom, 10)) as buffer FROM spatial;
    
  • Create a spatial index

      ij> CALL CreateSpatialIndex(null, 'SPATIAL', 'GEOM', '4326');
    
  • Perform a spatial query

      ij> SELECT ST_AsText(geom) FROM spatial s INNER JOIN table(HATBOX.MBR_INTERSECTS_ENV('APP', 'SPATIAL', -2, 2, -2, 2)) i on s.ID = i.HATBOX_JOIN_ID;
    

License

GeoDB is licensed under the MIT license.

More Information

General discussion takes place on the geodb google group. If you have any questions or comments please post a message there.

About

Spatial database bindings for Java.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 99.1%
  • Shell 0.9%