-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1376 from ebocher/st_isprojectedCRS
ST_IsProjectedCRS and ST_IsGeographicCRS
- Loading branch information
Showing
5 changed files
with
222 additions
and
1 deletion.
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
90 changes: 90 additions & 0 deletions
90
h2gis-functions/src/main/java/org/h2gis/functions/spatial/crs/ST_IsGeographicCRS.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,90 @@ | ||
/** | ||
* H2GIS is a library that brings spatial support to the H2 Database Engine | ||
* <a href="http://www.h2database.com">http://www.h2database.com</a>. H2GIS is developed by CNRS | ||
* <a href="http://www.cnrs.fr/">http://www.cnrs.fr/</a>. | ||
* | ||
* This code is part of the H2GIS project. H2GIS is free software; | ||
* you can redistribute it and/or modify it under the terms of the GNU | ||
* Lesser General Public License as published by the Free Software Foundation; | ||
* version 3.0 of the License. | ||
* | ||
* H2GIS is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License | ||
* for more details <http://www.gnu.org/licenses/>. | ||
* | ||
* | ||
* For more information, please consult: <a href="http://www.h2gis.org/">http://www.h2gis.org/</a> | ||
* or contact directly: info_at_h2gis.org | ||
*/ | ||
|
||
package org.h2gis.functions.spatial.crs; | ||
|
||
import org.cts.CRSFactory; | ||
import org.cts.crs.*; | ||
import org.cts.op.CoordinateOperation; | ||
import org.h2gis.api.DeterministicScalarFunction; | ||
import org.locationtech.jts.geom.Geometry; | ||
|
||
import java.sql.Connection; | ||
import java.sql.SQLException; | ||
import java.util.Map; | ||
|
||
/** | ||
* Method to check if the CRS of the geometry is geographic | ||
* @author Erwan Bocher, CNRS | ||
*/ | ||
public class ST_IsGeographicCRS extends DeterministicScalarFunction { | ||
|
||
private static CRSFactory crsf; | ||
private static SpatialRefRegistry srr = new SpatialRefRegistry(); | ||
private static Map<EPSGTuple, CoordinateOperation> copPool = new ST_Transform.CopCache(5); | ||
|
||
public ST_IsGeographicCRS() { | ||
addProperty(PROP_REMARKS, "ST_IsGeographicCRS takes a geometry and \n" | ||
+ "return true is the coordinate system is geographic, otherwise false. False is the geometry is null \n" + | ||
"and or if its srid is equals to 0."); | ||
} | ||
|
||
@Override | ||
public String getJavaStaticMethod() { | ||
return "execute"; | ||
} | ||
|
||
/** | ||
* Return true if the geometry has a geographic CRS | ||
* | ||
* @param geometry | ||
* @return | ||
* @throws SQLException | ||
*/ | ||
public static Boolean execute(Connection connection, Geometry geometry) throws SQLException { | ||
if (geometry == null) { | ||
return false; | ||
} | ||
int inputSRID = geometry.getSRID(); | ||
if (inputSRID == 0) { | ||
return false; | ||
} else { | ||
if (crsf == null) { | ||
crsf = new CRSFactory(); | ||
//Activate the CRSFactory and the internal H2 spatial_ref_sys registry to | ||
// manage Coordinate Reference Systems. | ||
crsf.getRegistryManager().addRegistry(srr); | ||
} | ||
srr.setConnection(connection); | ||
try { | ||
CoordinateReferenceSystem inputCRS = crsf.getCRS(srr.getRegistryName() + ":" + inputSRID); | ||
if(inputCRS instanceof Geographic2DCRS || inputCRS instanceof Geographic3DCRS){ | ||
return true; | ||
} | ||
|
||
} catch (CRSException ex) { | ||
throw new SQLException("Cannot create the CRS", ex); | ||
} finally { | ||
srr.setConnection(null); | ||
} | ||
} | ||
return false; | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
h2gis-functions/src/main/java/org/h2gis/functions/spatial/crs/ST_IsProjectedCRS.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,92 @@ | ||
/** | ||
* H2GIS is a library that brings spatial support to the H2 Database Engine | ||
* <a href="http://www.h2database.com">http://www.h2database.com</a>. H2GIS is developed by CNRS | ||
* <a href="http://www.cnrs.fr/">http://www.cnrs.fr/</a>. | ||
* | ||
* This code is part of the H2GIS project. H2GIS is free software; | ||
* you can redistribute it and/or modify it under the terms of the GNU | ||
* Lesser General Public License as published by the Free Software Foundation; | ||
* version 3.0 of the License. | ||
* | ||
* H2GIS is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License | ||
* for more details <http://www.gnu.org/licenses/>. | ||
* | ||
* | ||
* For more information, please consult: <a href="http://www.h2gis.org/">http://www.h2gis.org/</a> | ||
* or contact directly: info_at_h2gis.org | ||
*/ | ||
|
||
package org.h2gis.functions.spatial.crs; | ||
|
||
import org.cts.CRSFactory; | ||
import org.cts.crs.CRSException; | ||
import org.cts.crs.CoordinateReferenceSystem; | ||
import org.cts.crs.ProjectedCRS; | ||
import org.cts.op.CoordinateOperation; | ||
import org.h2gis.api.DeterministicScalarFunction; | ||
import org.locationtech.jts.geom.Geometry; | ||
|
||
import java.sql.Connection; | ||
import java.sql.SQLException; | ||
import java.util.Map; | ||
|
||
/** | ||
* Method to check if the CRS of the geometry is projected | ||
* @author Erwan Bocher, CNRS | ||
*/ | ||
public class ST_IsProjectedCRS extends DeterministicScalarFunction { | ||
|
||
private static CRSFactory crsf; | ||
private static SpatialRefRegistry srr = new SpatialRefRegistry(); | ||
private static Map<EPSGTuple, CoordinateOperation> copPool = new ST_Transform.CopCache(5); | ||
|
||
public ST_IsProjectedCRS() { | ||
addProperty(PROP_REMARKS, "ST_IsProjectedCRS takes a geometry and \n" | ||
+ "return true is the coordinate system is projected, otherwise false. False is the geometry is null \n" + | ||
"and or if its srid is equals to 0."); | ||
} | ||
|
||
@Override | ||
public String getJavaStaticMethod() { | ||
return "execute"; | ||
} | ||
|
||
/** | ||
* Return true if the CRS is a projected one | ||
* | ||
* @param geometry | ||
* @return | ||
* @throws java.sql.SQLException | ||
*/ | ||
public static Boolean execute(Connection connection, Geometry geometry) throws SQLException { | ||
if (geometry == null) { | ||
return false; | ||
} | ||
int inputSRID = geometry.getSRID(); | ||
if (inputSRID == 0) { | ||
return false; | ||
} else { | ||
if (crsf == null) { | ||
crsf = new CRSFactory(); | ||
//Activate the CRSFactory and the internal H2 spatial_ref_sys registry to | ||
// manage Coordinate Reference Systems. | ||
crsf.getRegistryManager().addRegistry(srr); | ||
} | ||
srr.setConnection(connection); | ||
try { | ||
CoordinateReferenceSystem inputCRS = crsf.getCRS(srr.getRegistryName() + ":" + inputSRID); | ||
if(inputCRS instanceof ProjectedCRS){ | ||
return true; | ||
} | ||
|
||
} catch (CRSException ex) { | ||
throw new SQLException("Cannot create the CRS", ex); | ||
} finally { | ||
srr.setConnection(null); | ||
} | ||
} | ||
return false; | ||
} | ||
} |
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