Java Code Examples for mil.nga.geopackage.core.srs.SpatialReferenceSystemDao#getOrCreateCode()
The following examples show how to use
mil.nga.geopackage.core.srs.SpatialReferenceSystemDao#getOrCreateCode() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FeatureInfoBuilder.java From geopackage-android-map with MIT License | 5 votes |
/** * Project the geometry into the provided projection * * @param geometryData geometry data * @param projection projection */ public void projectGeometry(GeoPackageGeometryData geometryData, Projection projection) { if (geometryData.getGeometry() != null) { try { SpatialReferenceSystemDao srsDao = DaoManager.createDao(featureDao.getDb().getConnectionSource(), SpatialReferenceSystem.class); int srsId = geometryData.getSrsId(); SpatialReferenceSystem srs = srsDao.queryForId((long) srsId); if (!projection.equals(srs.getOrganization(), srs.getOrganizationCoordsysId())) { Projection geomProjection = srs.getProjection(); ProjectionTransform transform = geomProjection.getTransformation(projection); Geometry projectedGeometry = transform.transform(geometryData.getGeometry()); geometryData.setGeometry(projectedGeometry); SpatialReferenceSystem projectionSrs = srsDao.getOrCreateCode(projection.getAuthority(), Long.parseLong(projection.getCode())); geometryData.setSrsId((int) projectionSrs.getSrsId()); } } catch (SQLException e) { throw new GeoPackageException("Failed to project geometry to projection with Authority: " + projection.getAuthority() + ", Code: " + projection.getCode(), e); } } }
Example 2
Source File: FeatureCoreGenerator.java From geopackage-core-java with MIT License | 5 votes |
/** * Create the Spatial Reference System * * @throws SQLException * upon error */ public void createSrs() throws SQLException { SpatialReferenceSystemDao srsDao = geoPackage .getSpatialReferenceSystemDao(); Projection srsProjection = getSrsProjection(); srs = srsDao.getOrCreateCode(srsProjection.getAuthority(), Long.parseLong(srsProjection.getCode())); }
Example 3
Source File: GeoPackageExample.java From geopackage-android with MIT License | 4 votes |
private static void createFeatures(GeoPackage geoPackage) throws SQLException { SpatialReferenceSystemDao srsDao = geoPackage .getSpatialReferenceSystemDao(); SpatialReferenceSystem srs = srsDao.getOrCreateCode( ProjectionConstants.AUTHORITY_EPSG, (long) ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM); geoPackage.createGeometryColumnsTable(); createFeatures1(geoPackage, srs); createFeatures2(geoPackage, srs); }
Example 4
Source File: GeoPackageExample.java From geopackage-android with MIT License | 4 votes |
private static void createNonLinearGeometryTypesExtension( GeoPackage geoPackage) throws SQLException { SpatialReferenceSystemDao srsDao = geoPackage .getSpatialReferenceSystemDao(); SpatialReferenceSystem srs = srsDao.getOrCreateCode( ProjectionConstants.AUTHORITY_EPSG, (long) ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM); GeometryExtensions extensions = new GeometryExtensions(geoPackage); String tableName = "non_linear_geometries"; List<Geometry> geometries = new ArrayList<>(); List<String> geometryNames = new ArrayList<>(); CircularString circularString = new CircularString(); circularString.addPoint(new Point(-122.358, 47.653)); circularString.addPoint(new Point(-122.348, 47.649)); circularString.addPoint(new Point(-122.348, 47.658)); circularString.addPoint(new Point(-122.358, 47.658)); circularString.addPoint(new Point(-122.358, 47.653)); for (int i = GeometryCodes.getCode(GeometryType.CIRCULARSTRING); i <= GeometryCodes.getCode(GeometryType.SURFACE); i++) { GeometryType geometryType = GeometryCodes.getGeometryType(i); extensions.getOrCreate(tableName, GEOMETRY_COLUMN, geometryType); Geometry geometry = null; String name = geometryType.getName().toLowerCase(); switch (geometryType) { case CIRCULARSTRING: geometry = circularString; break; case COMPOUNDCURVE: CompoundCurve compoundCurve = new CompoundCurve(); compoundCurve.addLineString(circularString); geometry = compoundCurve; break; case CURVEPOLYGON: CurvePolygon<CircularString> curvePolygon = new CurvePolygon<>(); curvePolygon.addRing(circularString); geometry = curvePolygon; break; case MULTICURVE: MultiLineString multiCurve = new MultiLineString(); multiCurve.addLineString(circularString); geometry = multiCurve; break; case MULTISURFACE: MultiPolygon multiSurface = new MultiPolygon(); Polygon polygon = new Polygon(); polygon.addRing(circularString); multiSurface.addPolygon(polygon); geometry = multiSurface; break; case CURVE: CompoundCurve curve = new CompoundCurve(); curve.addLineString(circularString); geometry = curve; break; case SURFACE: CurvePolygon<CircularString> surface = new CurvePolygon<>(); surface.addRing(circularString); geometry = surface; break; default: throw new GeoPackageException("Unexpected Geometry Type: " + geometryType); } geometries.add(geometry); geometryNames.add(name); } createFeatures(geoPackage, srs, tableName, GeometryType.GEOMETRY, geometries, geometryNames); }
Example 5
Source File: GeoPackageExample.java From geopackage-java with MIT License | 4 votes |
private static void createFeatures(GeoPackage geoPackage) throws SQLException { SpatialReferenceSystemDao srsDao = geoPackage .getSpatialReferenceSystemDao(); SpatialReferenceSystem srs = srsDao.getOrCreateCode( ProjectionConstants.AUTHORITY_EPSG, (long) ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM); geoPackage.createGeometryColumnsTable(); createFeatures1(geoPackage, srs); createFeatures2(geoPackage, srs); }
Example 6
Source File: GeoPackageExample.java From geopackage-java with MIT License | 4 votes |
private static void createNonLinearGeometryTypesExtension( GeoPackage geoPackage) throws SQLException { SpatialReferenceSystemDao srsDao = geoPackage .getSpatialReferenceSystemDao(); SpatialReferenceSystem srs = srsDao.getOrCreateCode( ProjectionConstants.AUTHORITY_EPSG, (long) ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM); GeometryExtensions extensions = new GeometryExtensions(geoPackage); String tableName = "non_linear_geometries"; List<Geometry> geometries = new ArrayList<>(); List<String> geometryNames = new ArrayList<>(); CircularString circularString = new CircularString(); circularString.addPoint(new Point(-122.358, 47.653)); circularString.addPoint(new Point(-122.348, 47.649)); circularString.addPoint(new Point(-122.348, 47.658)); circularString.addPoint(new Point(-122.358, 47.658)); circularString.addPoint(new Point(-122.358, 47.653)); for (int i = GeometryCodes .getCode(GeometryType.CIRCULARSTRING); i <= GeometryCodes .getCode(GeometryType.SURFACE); i++) { GeometryType geometryType = GeometryCodes.getGeometryType(i); extensions.getOrCreate(tableName, GEOMETRY_COLUMN, geometryType); Geometry geometry = null; String name = geometryType.getName().toLowerCase(); switch (geometryType) { case CIRCULARSTRING: geometry = circularString; break; case COMPOUNDCURVE: CompoundCurve compoundCurve = new CompoundCurve(); compoundCurve.addLineString(circularString); geometry = compoundCurve; break; case CURVEPOLYGON: CurvePolygon<CircularString> curvePolygon = new CurvePolygon<>(); curvePolygon.addRing(circularString); geometry = curvePolygon; break; case MULTICURVE: MultiLineString multiCurve = new MultiLineString(); multiCurve.addLineString(circularString); geometry = multiCurve; break; case MULTISURFACE: MultiPolygon multiSurface = new MultiPolygon(); Polygon polygon = new Polygon(); polygon.addRing(circularString); multiSurface.addPolygon(polygon); geometry = multiSurface; break; case CURVE: CompoundCurve curve = new CompoundCurve(); curve.addLineString(circularString); geometry = curve; break; case SURFACE: CurvePolygon<CircularString> surface = new CurvePolygon<>(); surface.addRing(circularString); geometry = surface; break; default: throw new GeoPackageException( "Unexpected Geometry Type: " + geometryType); } geometries.add(geometry); geometryNames.add(name); } createFeatures(geoPackage, srs, tableName, GeometryType.GEOMETRY, geometries, geometryNames); }