-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added extra functions for hibernate spatial capabilities, closes #13,…
… pull request submitted by jacques-finalist
- Loading branch information
Showing
10 changed files
with
703 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package geodb.aggregate; | ||
|
||
import java.sql.Connection; | ||
import java.sql.SQLException; | ||
|
||
import com.vividsolutions.jts.geom.Geometry; | ||
|
||
public class Extent extends GeoAggregateFunction { | ||
|
||
private Geometry result; | ||
|
||
@Override | ||
protected void add(Geometry geometry) { | ||
if (result == null) { | ||
result = geometry; | ||
} else { | ||
if (geometry != null) { | ||
result = result.union(geometry.getEnvelope()); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
protected Geometry getGeometryResult() { | ||
if (result != null) { | ||
return result.getEnvelope(); | ||
} | ||
return null; | ||
} | ||
|
||
public void init(Connection arg0) throws SQLException { | ||
result = null; | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
core/src/main/java/geodb/aggregate/GeoAggregateFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package geodb.aggregate; | ||
|
||
import geodb.GeoDB; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.sql.SQLException; | ||
import java.sql.Types; | ||
|
||
import org.h2.api.AggregateFunction; | ||
|
||
import com.vividsolutions.jts.geom.Geometry; | ||
import com.vividsolutions.jts.io.InputStreamInStream; | ||
import com.vividsolutions.jts.io.ParseException; | ||
import com.vividsolutions.jts.io.WKBReader; | ||
|
||
public abstract class GeoAggregateFunction implements AggregateFunction { | ||
|
||
private Geometry createGeometry(ByteArrayInputStream stream) { | ||
InputStreamInStream inputStreamInStream = new InputStreamInStream(stream); | ||
Geometry geometry = null; | ||
try { | ||
geometry = new WKBReader().read(inputStreamInStream); | ||
} catch (IOException e) { | ||
throw new IllegalArgumentException("given geometry can not be found", e); | ||
} catch (ParseException e) { | ||
throw new IllegalArgumentException("given geometry is not valid", e); | ||
} | ||
return geometry; | ||
|
||
} | ||
|
||
protected abstract void add(Geometry geometry); | ||
|
||
protected abstract Geometry getGeometryResult(); | ||
|
||
public final void add(Object arg0) throws SQLException { | ||
if (arg0 != null) { | ||
Geometry geometry = createGeometry((ByteArrayInputStream) arg0); | ||
if (geometry != null) { | ||
add(geometry); | ||
} | ||
} | ||
} | ||
|
||
public final Object getResult() throws SQLException { | ||
Geometry geometryResult = getGeometryResult(); | ||
if (geometryResult != null) { | ||
return GeoDB.gToWKB(geometryResult); | ||
} | ||
return null; | ||
} | ||
|
||
public final int getType(int[] arg0) throws SQLException { | ||
return Types.BLOB; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package geodb.aggregate; | ||
|
||
import java.sql.Connection; | ||
import java.sql.SQLException; | ||
|
||
import com.vividsolutions.jts.geom.Geometry; | ||
|
||
public class Union extends GeoAggregateFunction { | ||
|
||
private Geometry result; | ||
|
||
@Override | ||
protected void add(Geometry geometry) { | ||
if (result == null) { | ||
result = geometry; | ||
} else { | ||
if (geometry != null) { | ||
result = result.union(geometry); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
protected Geometry getGeometryResult() { | ||
return result; | ||
} | ||
|
||
public void init(Connection arg0) throws SQLException { | ||
result = null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.