org.opengis.referencing.crs.CoordinateReferenceSystem Java Examples
The following examples show how to use
org.opengis.referencing.crs.CoordinateReferenceSystem.
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: CrsUtilities.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
/** * Fill the prj file with the actual map projection. * * @param filePath the path to the regarding data or prj file. * @param extention the extention of the data file. If <code>null</code>, the crs is written to filePath directly. * @param crs the {@link CoordinateReferenceSystem} to write. * * @throws IOException */ @SuppressWarnings("nls") public static void writeProjectionFile( String filePath, String extention, CoordinateReferenceSystem crs ) throws IOException { /* * fill a prj file */ String prjPath = null; if (extention != null && filePath.toLowerCase().endsWith("." + extention)) { int dotLoc = filePath.lastIndexOf("."); prjPath = filePath.substring(0, dotLoc); prjPath = prjPath + ".prj"; } else { if (!filePath.endsWith(".prj")) { prjPath = filePath + ".prj"; } else { prjPath = filePath; } } try (BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(prjPath))) { bufferedWriter.write(crs.toWKT()); } }
Example #2
Source File: SwtMapPane.java From gama with GNU General Public License v3.0 | 6 votes |
public void setCrs(final CoordinateReferenceSystem crs) { try { final ReferencedEnvelope rEnv = getDisplayArea(); final CoordinateReferenceSystem sourceCRS = rEnv.getCoordinateReferenceSystem(); final CoordinateReferenceSystem targetCRS = crs; final MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS); final com.vividsolutions.jts.geom.Envelope newJtsEnv = JTS.transform(rEnv, transform); final ReferencedEnvelope newEnvelope = new ReferencedEnvelope(newJtsEnv, targetCRS); content.getViewport().setBounds(newEnvelope); fullExtent = null; doSetDisplayArea(newEnvelope); } catch (final Exception e) { e.printStackTrace(); } }
Example #3
Source File: CommonAuthorityFactory.java From sis with Apache License 2.0 | 6 votes |
/** * Returns the "Computer display" reference system (CRS:1). This is rarely used. */ private synchronized CoordinateReferenceSystem displayCRS() throws FactoryException { if (displayCRS == null) { final CSFactory csFactory = DefaultFactories.forBuildin(CSFactory.class); final CartesianCS cs = csFactory.createCartesianCS( Collections.singletonMap(CartesianCS.NAME_KEY, "Computer display"), csFactory.createCoordinateSystemAxis(Collections.singletonMap(CartesianCS.NAME_KEY, "i"), "i", AxisDirection.EAST, Units.PIXEL), csFactory.createCoordinateSystemAxis(Collections.singletonMap(CartesianCS.NAME_KEY, "j"), "j", AxisDirection.SOUTH, Units.PIXEL)); final Map<String,Object> properties = new HashMap<>(4); properties.put(EngineeringDatum.NAME_KEY, cs.getName()); properties.put(EngineeringDatum.ANCHOR_POINT_KEY, "Origin is in upper left."); displayCRS = DefaultFactories.forBuildin(CRSFactory.class).createEngineeringCRS(properties, DefaultFactories.forBuildin(DatumFactory.class).createEngineeringDatum(properties), cs); } return displayCRS; }
Example #4
Source File: TestTca.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
public void testNewTca() throws Exception { HashMap<String, Double> envelopeParams = HMTestMaps.getEnvelopeparams(); CoordinateReferenceSystem crs = HMTestMaps.getCrs(); double[][] flowData = HMTestMaps.flowData; GridCoverage2D flowCoverage = CoverageUtilities.buildCoverage("flow", flowData, envelopeParams, crs, true); OmsTca tca = new OmsTca(); tca.inFlow = flowCoverage; tca.pm = pm; tca.process(); GridCoverage2D tcaCoverage = tca.outTca; // PrintUtilities.printCoverageData(tcaCoverage); checkMatrixEqual(tcaCoverage.getRenderedImage(), HMTestMaps.tcaData); }
Example #5
Source File: TestMapcalc.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
public void testMapcalc3() throws Exception { double[][] elevationData = HMTestMaps.pitData; HashMap<String, Double> envelopeParams = HMTestMaps.getEnvelopeparams(); CoordinateReferenceSystem crs = HMTestMaps.getCrs(); GridCoverage2D elevationCoverage = CoverageUtilities.buildCoverage("ele", elevationData, envelopeParams, crs, true); List<GridCoverage2D> maps = Arrays.asList(elevationCoverage); OmsMapcalc mapcalc = new OmsMapcalc(); mapcalc.inRasters = maps; mapcalc.pFunction = "images{ele=read; dest=write;} dest = xres()*yres();"; mapcalc.process(); GridCoverage2D outMap = mapcalc.outRaster; RenderedImage renderedImage = outMap.getRenderedImage(); // printImage(renderedImage); checkEqualsSinlgeValue(renderedImage, 900.0, 0.000000001); }
Example #6
Source File: GeoServiceImpl.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
@Override public Geometry transform(Geometry geometry, CoordinateReferenceSystem sourceCrs, CoordinateReferenceSystem targetCrs) throws GeomajasException { if (sourceCrs == targetCrs) { // NOPMD // only works when the caching of the CRSs works return geometry; } Crs source, target; if (sourceCrs instanceof Crs) { source = (Crs) sourceCrs; } else { source = getCrs2(getCodeFromCrs(sourceCrs)); } if (targetCrs instanceof Crs) { target = (Crs) targetCrs; } else { target = getCrs2(getCodeFromCrs(targetCrs)); } CrsTransform crsTransform = getCrsTransform(source, target); return transform(geometry, crsTransform); }
Example #7
Source File: EnvelopeOperationTest.java From sis with Apache License 2.0 | 6 votes |
/** * Creates a feature type with a bounds operation. * The feature contains the following properties: * * <ul> * <li>{@code name} as a {@link String}</li> * <li>{@code classes} as a {@link Polygon}</li> * <li>{@code climbing wall} as a {@link Point}</li> * <li>{@code gymnasium} as a {@link Polygon}</li> * <li>{@code sis:geometry} as a link to the default geometry</li> * <li>{@code bounds} as the feature envelope attribute.</li> * </ul> * * @param defaultGeometry 1 for using "classes" as the default geometry, or 3 for "gymnasium". * @return the feature for a school. */ private static DefaultFeatureType school(final int defaultGeometry) throws FactoryException { final DefaultAttributeType<?> standardCRS = new DefaultAttributeType<>( name(AttributeConvention.CRS_CHARACTERISTIC), CoordinateReferenceSystem.class, 1, 1, HardCodedCRS.WGS84_φλ); final DefaultAttributeType<?> normalizedCRS = new DefaultAttributeType<>( name(AttributeConvention.CRS_CHARACTERISTIC), CoordinateReferenceSystem.class, 1, 1, HardCodedCRS.WGS84); final AbstractIdentifiedType[] attributes = { new DefaultAttributeType<>(name("name"), String.class, 1, 1, null), new DefaultAttributeType<>(name("classes"), Polygon.class, 1, 1, null, standardCRS), new DefaultAttributeType<>(name("climbing wall"), Point.class, 1, 1, null, standardCRS), new DefaultAttributeType<>(name("gymnasium"), Polygon.class, 1, 1, null, normalizedCRS), null, null }; attributes[4] = FeatureOperations.link(name(AttributeConvention.GEOMETRY_PROPERTY), attributes[defaultGeometry]); attributes[5] = FeatureOperations.envelope(name("bounds"), null, attributes); return new DefaultFeatureType(name("school"), false, null, attributes); }
Example #8
Source File: CoordinateOperationsTest.java From sis with Apache License 2.0 | 6 votes |
/** * Tests {@link CoordinateOperations#wrapAroundChanges(CoordinateReferenceSystem, CoordinateSystem)}. */ @Test @DependsOnMethod("testIsWrapAround") public void testWrapAroundChanges() { CoordinateReferenceSystem sourceCRS = HardCodedCRS.WGS84_3D; CoordinateSystem targetCS = HardCodedCS.GEODETIC_2D; assertTrue("(λ,φ,h) → (λ,φ)", CoordinateOperations.wrapAroundChanges(sourceCRS, targetCS).isEmpty()); sourceCRS = HardCodedCRS.WGS84_3D.forConvention(AxesConvention.POSITIVE_RANGE); assertArrayEquals("(λ′,φ,h) → (λ,φ)", new Integer[] {0}, CoordinateOperations.wrapAroundChanges(sourceCRS, targetCS).toArray()); targetCS = HardCodedCS.GEODETIC_φλ; assertArrayEquals("(λ′,φ,h) → (φ,λ)", new Integer[] {1}, CoordinateOperations.wrapAroundChanges(sourceCRS, targetCS).toArray()); sourceCRS = HardCodedConversions.mercator((GeographicCRS) sourceCRS); assertArrayEquals("(λ′,φ,h) → (φ,λ)", new Integer[] {1}, CoordinateOperations.wrapAroundChanges(sourceCRS, targetCS).toArray()); }
Example #9
Source File: OperationMethodCrsProvider.java From snap-desktop with GNU General Public License v3.0 | 6 votes |
@Override public CoordinateReferenceSystem getCRS(final GeoPos referencePos, ParameterValueGroup parameters, GeodeticDatum datum) throws FactoryException { final CRSFactory crsFactory = ReferencingFactoryFinder.getCRSFactory(null); // in some cases, depending on the parameters set, the effective transformation can be different // from the transformation given by the OperationMethod. // So we create a new one final MathTransformFactory mtFactory = ReferencingFactoryFinder.getMathTransformFactory(null); final MathTransform transform = mtFactory.createParameterizedTransform(parameters); final DefaultOperationMethod operationMethod = new DefaultOperationMethod(transform); final Conversion conversion = new DefiningConversion(AbstractIdentifiedObject.getProperties(operationMethod), operationMethod, transform); final HashMap<String, Object> baseCrsProperties = new HashMap<String, Object>(); baseCrsProperties.put("name", datum.getName().getCode()); GeographicCRS baseCrs = crsFactory.createGeographicCRS(baseCrsProperties, datum, DefaultEllipsoidalCS.GEODETIC_2D); final HashMap<String, Object> projProperties = new HashMap<String, Object>(); projProperties.put("name", conversion.getName().getCode() + " / " + datum.getName().getCode()); return crsFactory.createProjectedCRS(projProperties, baseCrs, conversion, DefaultCartesianCS.PROJECTED); }
Example #10
Source File: CRS.java From sis with Apache License 2.0 | 6 votes |
/** * Returns the first temporal coordinate reference system found in the given CRS, or {@code null} if there is none. * If the given CRS is already an instance of {@code TemporalCRS}, then this method returns it as-is. * Otherwise if the given CRS is compound, then this method searches for the first temporal component * in the order of the {@linkplain #getSingleComponents(CoordinateReferenceSystem) single components list}. * * @param crs the coordinate reference system, or {@code null}. * @return the first temporal CRS, or {@code null} if none. * * @category information */ public static TemporalCRS getTemporalComponent(final CoordinateReferenceSystem crs) { if (crs instanceof TemporalCRS) { return (TemporalCRS) crs; } if (crs instanceof CompoundCRS) { final CompoundCRS cp = (CompoundCRS) crs; for (final CoordinateReferenceSystem c : cp.getComponents()) { final TemporalCRS candidate = getTemporalComponent(c); if (candidate != null) { return candidate; } } } return null; }
Example #11
Source File: TestExtractNetwork.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
/** * Test module with mode=0. */ public void testExtractNetwork0() throws Exception { HashMap<String, Double> envelopeParams = HMTestMaps.getEnvelopeparams(); CoordinateReferenceSystem crs = HMTestMaps.getCrs(); double[][] flowData = HMTestMaps.flowData; GridCoverage2D flowCoverage = CoverageUtilities.buildCoverage("flow", flowData, envelopeParams, crs, true); double[][] tcaData = HMTestMaps.tcaData; GridCoverage2D tcaCoverage = CoverageUtilities.buildCoverage("tca", tcaData, envelopeParams, crs, true); OmsExtractNetwork extractNetwork = new OmsExtractNetwork(); extractNetwork.pm = pm; extractNetwork.inFlow = flowCoverage; extractNetwork.inTca = tcaCoverage; extractNetwork.pMode = Variables.TCA; extractNetwork.pThres = 5; extractNetwork.process(); GridCoverage2D networkCoverage = extractNetwork.outNet; checkMatrixEqual(networkCoverage.getRenderedImage(), HMTestMaps.extractNet0Data, 0.01); }
Example #12
Source File: OmsGridsGenerator.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
private void createPolygons( CoordinateReferenceSystem crs, GeometryFactory gf, List<Geometry> polygons ) { outMap = new DefaultFeatureCollection(); SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setName(POLYGON); b.setCRS(crs); b.add("the_geom", Polygon.class); b.add("id", Long.class); SimpleFeatureType type = b.buildFeatureType(); SimpleFeatureBuilder fbuilder = new SimpleFeatureBuilder(type); long index = 0; int numGeometries = polygons.size(); for( int i = 0; i < numGeometries; i++ ) { Geometry geometry = polygons.get(i); Object[] values = new Object[]{geometry, index++}; fbuilder.addAll(values); SimpleFeature feature = fbuilder.buildFeature(null); ((DefaultFeatureCollection) outMap).add(feature); } }
Example #13
Source File: CoordManager.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** * Gets the WGS84 coordinate reference object. * * @return the WGS84 coordinate reference system */ public CoordinateReferenceSystem getWGS84() { if (defaultCRS == null) { defaultCRS = getCRS(WGS84); } return defaultCRS; }
Example #14
Source File: ComparisonWithEPSG.java From sis with Apache License 2.0 | 5 votes |
/** * Compares a projected CRS parsed from a WKT with a the CRS built from EPSG database. * The later is taken as the reference. */ private static void compare(final String wkt, final int epsg) throws FactoryException { final CoordinateReferenceSystem crs = CRS.fromWKT(wkt); final EPSGFactory factory = TestFactorySource.factory; assumeNotNull(factory); final CoordinateReferenceSystem reference = factory.createProjectedCRS(Integer.toString(epsg)); assertEqualsIgnoreMetadata(reference, crs); }
Example #15
Source File: GeoServiceTransformableAreaTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
@Test public void transformGeometryJtsCrs() throws Exception { Geometry geometry = getLineString(); CoordinateReferenceSystem source = CRS.decode(LONLAT); CoordinateReferenceSystem target = CRS.decode(LAMBERT72); geometry = geoService.transform(geometry, source, target); assertTransformedLineString(geometry); }
Example #16
Source File: CoverageUtilities.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
public static GridGeometry2D gridGeometryFromRegionParams( HashMap<String, Double> envelopeParams, CoordinateReferenceSystem crs ) { double west = envelopeParams.get(WEST); double south = envelopeParams.get(SOUTH); double east = envelopeParams.get(EAST); double north = envelopeParams.get(NORTH); int rows = envelopeParams.get(ROWS).intValue(); int cols = envelopeParams.get(COLS).intValue(); return gridGeometryFromRegionValues(north, south, east, west, cols, rows, crs); }
Example #17
Source File: JTS.java From sis with Apache License 2.0 | 5 votes |
/** * If the given geometry is an implementation of this library, returns its coordinate reference system. * Otherwise returns {@code null}. * * @see #tryTransform(Object, CoordinateOperation, CoordinateReferenceSystem) */ @Override final CoordinateReferenceSystem tryGetCoordinateReferenceSystem(final Object geometry) throws FactoryException { if (geometry instanceof Geometry) { return org.apache.sis.internal.feature.jts.JTS.getCoordinateReferenceSystem((Geometry) geometry); } else { return super.tryGetCoordinateReferenceSystem(geometry); } }
Example #18
Source File: GeoServiceImpl.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
/** * Finish service initialization. * * @throws GeomajasException oops */ @PostConstruct protected void postConstruct() throws GeomajasException { if (null != crsDefinitions) { for (CrsInfo crsInfo : crsDefinitions.values()) { try { CoordinateReferenceSystem crs = CRS.parseWKT(crsInfo.getCrsWkt()); String code = crsInfo.getKey(); crsCache.put(code, CrsFactory.getCrs(code, crs)); } catch (FactoryException e) { throw new GeomajasException(e, ExceptionCode.CRS_DECODE_FAILURE_FOR_MAP, crsInfo.getKey()); } } } if (null != crsTransformDefinitions) { for (CrsTransformInfo crsTransformInfo : crsTransformDefinitions.values()) { String key = getTransformKey(crsTransformInfo); transformCache.put(key, getCrsTransform(key, crsTransformInfo)); } } GeometryFactory factory = new GeometryFactory(); EMPTY_GEOMETRIES.put(Point.class, factory.createPoint((Coordinate) null)); EMPTY_GEOMETRIES.put(LineString.class, factory.createLineString((Coordinate[]) null)); EMPTY_GEOMETRIES.put(Polygon.class, factory.createPolygon(null, null)); EMPTY_GEOMETRIES.put(MultiPoint.class, factory.createMultiPoint((Coordinate[]) null)); EMPTY_GEOMETRIES.put(MultiLineString.class, factory.createMultiLineString((LineString[]) null)); // cast needed! EMPTY_GEOMETRIES.put(MultiPolygon.class, factory.createMultiPolygon((Polygon[]) null)); // cast needed! EMPTY_GEOMETRIES.put(Geometry.class, factory.createGeometryCollection(null)); }
Example #19
Source File: PolygonAreaCalculator.java From geowave with Apache License 2.0 | 5 votes |
public double getAreaSimple(final Geometry polygon) throws Exception { final Point centroid = polygon.getCentroid(); final CoordinateReferenceSystem equalAreaCRS = lookupUtmCrs(centroid.getY(), centroid.getX()); final MathTransform transform = CRS.findMathTransform(DefaultGeographicCRS.WGS84, equalAreaCRS, true); final Geometry transformedPolygon = JTS.transform(polygon, transform); return transformedPolygon.getArea() * SQM_2_SQKM; }
Example #20
Source File: TestGc.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("nls") public void testGc() { HashMap<String, Double> envelopeParams = HMTestMaps.getEnvelopeparams(); CoordinateReferenceSystem crs = HMTestMaps.getCrs(); double[][] slopeData = HMTestMaps.slopeData; double[][] networkData = HMTestMaps.extractNet1Data; double[][] cp9Data = HMTestMaps.cp9Data; GridCoverage2D slopeGC = CoverageUtilities.buildCoverage("slope", slopeData, envelopeParams, crs, true); GridCoverage2D networkGC = CoverageUtilities.buildCoverage("net", networkData, envelopeParams, crs, true); GridCoverage2D cp9GC = CoverageUtilities.buildCoverage("cp9", cp9Data, envelopeParams, crs, true); OmsGc gc = new OmsGc(); gc.inSlope = slopeGC; gc.inNetwork = networkGC; gc.inCp9 = cp9GC; gc.pTh=7; gc.process(); GridCoverage2D outGCClasses= gc.outClasses; GridCoverage2D outGcAggregate = gc.outAggregateClasses; checkMatrixEqual(outGCClasses.getRenderedImage(), HMTestMaps.cp9GCData); checkMatrixEqual(outGcAggregate.getRenderedImage(), HMTestMaps.cp3GCData); }
Example #21
Source File: CoordinateOperationRegistryTest.java From sis with Apache License 2.0 | 5 votes |
/** * Tests <cite>"NTF (Paris) to WGS 84 (1)"</cite> operation with three-dimensional source and target CRS. * {@link CoordinateOperationRegistry} should be able to find the operation despite the difference in * number of dimensions. * * @throws ParseException if a CRS used in this test can not be parsed. * @throws FactoryException if the operation can not be created. * @throws TransformException if an error occurred while converting the test points. */ @Test @DependsOnMethod("testLongitudeRotationBetweenConformCRS") public void testLongitudeRotationBetweenGeographic3D() throws ParseException, FactoryException, TransformException { final CoordinateReferenceSystem sourceCRS = parse( "GeodeticCRS[“NTF (Paris)”,\n" + " $NTF,\n" + " PrimeMeridian[“Paris”, 2.5969213],\n" + " CS[ellipsoidal, 3],\n" + " Axis[“Latitude (φ)”, NORTH, Unit[“grad”, 0.015707963267948967]],\n" + " Axis[“Longitude (λ)”, EAST, Unit[“grad”, 0.015707963267948967]],\n" + " Axis[“Height (h)”, UP, Unit[“m”, 1]]]"); final CoordinateReferenceSystem targetCRS = CommonCRS.WGS84.geographic3D(); final CoordinateOperation operation = createOperation(sourceCRS, targetCRS); verifyNTF(operation, "geog3D domain", false); transform = operation.getMathTransform(); tolerance = Formulas.ANGULAR_TOLERANCE; zTolerance = Formulas.LINEAR_TOLERANCE; zDimension = new int[] {2}; λDimension = new int[] {1}; tolerance = zTolerance; // Because GeoAPI 3.0 does not distinguish z axis from other axes (fixed in GeoAPI 3.1). verifyTransform(new double[] {54.271680278, 0.098269657, 20.00}, // in grads east of Paris new double[] {48.844443528, 2.424952028, 63.15}); // in degrees east of Greenwich validate(); }
Example #22
Source File: EllipsoidalHeightCombinerTest.java From sis with Apache License 2.0 | 5 votes |
/** * Tests {@link EllipsoidalHeightCombiner#createCompoundCRS EllipsoidalHeightCombiner.createCompoundCRS(…)} * with a geographic CRS. * * @throws FactoryException if a CRS can not be created. */ @Test public void testGeographicCRS() throws FactoryException { final EllipsoidalHeightCombiner services = create(); final Map<String,String> properties = Collections.singletonMap(CoordinateReferenceSystem.NAME_KEY, "WGS 84 (4D)"); final GeographicCRS horizontal = HardCodedCRS.WGS84; final GeographicCRS volumetric = HardCodedCRS.WGS84_3D; final VerticalCRS vertical = HardCodedCRS.ELLIPSOIDAL_HEIGHT; final TemporalCRS temporal = HardCodedCRS.TIME; final VerticalCRS geoidal = HardCodedCRS.GRAVITY_RELATED_HEIGHT; /* * createCompoundCRS(…) should not combine GeographicCRS with non-ellipsoidal height. */ CoordinateReferenceSystem compound = services.createCompoundCRS(properties, horizontal, geoidal, temporal); assertArrayEqualsIgnoreMetadata(new SingleCRS[] {horizontal, geoidal, temporal}, CRS.getSingleComponents(compound).toArray()); /* * createCompoundCRS(…) should combine GeographicCRS with ellipsoidal height. */ compound = services.createCompoundCRS(properties, horizontal, vertical); assertArrayEqualsIgnoreMetadata(new SingleCRS[] {volumetric}, CRS.getSingleComponents(compound).toArray()); /* * createCompoundCRS(…) should combine GeographicCRS with ellipsoidal height and keep time. */ compound = services.createCompoundCRS(properties, horizontal, vertical, temporal); assertArrayEqualsIgnoreMetadata(new SingleCRS[] {volumetric, temporal}, CRS.getSingleComponents(compound).toArray()); /* * Non-standard feature: accept (VerticalCRS + GeodeticCRS) order. * The test below use the reverse order for all axes compared to the previous test. */ compound = services.createCompoundCRS(properties, temporal, vertical, HardCodedCRS.WGS84_φλ); final Object[] components = CRS.getSingleComponents(compound).toArray(); assertEquals(2, components.length); assertEqualsIgnoreMetadata(temporal, components[0]); assertInstanceOf("Shall be a three-dimensional geographic CRS.", GeographicCRS.class, components[1]); assertAxisDirectionsEqual("Shall be a three-dimensional geographic CRS.", ((CoordinateReferenceSystem) components[1]).getCoordinateSystem(), AxisDirection.UP, AxisDirection.NORTH, AxisDirection.EAST); }
Example #23
Source File: GeocoderUtilService.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
/** * Transform a {@link Envelope} from the source to the target CRS. * * @param source source geometry * @param sourceCrs source CRS * @param targetCrs target CRS * @return transformed source, now in target CRS * @throws GeomajasException building the transformation or doing the transformation is not possible */ public Envelope transform(Envelope source, CoordinateReferenceSystem sourceCrs, CoordinateReferenceSystem targetCrs) throws GeomajasException { if (sourceCrs == targetCrs) { // NOPMD // only works when the caching of the CRSs works return source; } CrsTransform crsTransform = geoService.getCrsTransform(sourceCrs, targetCrs); return geoService.transform(source, crsTransform); }
Example #24
Source File: TestRaster.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
public void testRaster() throws Exception { RegionMap e = HMTestMaps.envelopeParams; Raster r1 = new Raster(e.getCols(), e.getRows(), e.getXres(), e.getWest(), e.getNorth(), "EPSG:32632"); double[][] elevationData = HMTestMaps.mapData; HashMap<String, Double> eP = HMTestMaps.envelopeParams; CoordinateReferenceSystem crs = HMTestMaps.crs; GridCoverage2D elevationCoverage = CoverageUtilities.buildCoverage("elevation", elevationData, eP, crs, true); Raster r2 = new Raster(elevationCoverage); Raster r3 = new Raster(r2); for( int r = 0; r < elevationData.length; r++ ) { for( int c = 0; c < elevationData[0].length; c++ ) { r1.setValueAt(c, r, elevationData[r][c]); r3.setValueAt(c, r, elevationData[r][c]); } } check(5, 6, r1, r2, r3); check(3, 4, r1, r2, r3); check(5, 3, r1, r2, r3); check(4, 4, r1, r2, r3); }
Example #25
Source File: CacheKeyServiceImpl.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
private String getCacheId(Object value) { if (value instanceof CacheableObject) { return ((CacheableObject) value).getCacheId(); } else if (value instanceof Crs) { return ((Crs) value).getId(); } else if (value instanceof CoordinateReferenceSystem) { return ((CoordinateReferenceSystem) value).toWKT(); } else if (value instanceof Geometry) { return ((Geometry) value).toText(); } else if (value instanceof Filter) { return value.toString(); } else if (value instanceof Integer) { return Integer.toString((Integer) value); } else if (value instanceof String) { return value.toString(); } else { try { log.debug("Serializing {} for unique id", value.getClass().getName()); ByteArrayOutputStream baos = new ByteArrayOutputStream(SERIALIZED_BUFFER_SIZE); JBossObjectOutputStream serialize = new JBossObjectOutputStream(baos); serialize.writeObject(value); serialize.flush(); serialize.close(); return baos.toString("UTF-8"); } catch (IOException ioe) { String fallback = value.toString(); log.error("Could not serialize " + value + ", falling back to toString() which may cause problems.", ioe); return fallback; } } }
Example #26
Source File: CoverageUtilities.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
/** * Creates a {@link GridCoverage2D coverage} from the {@link RenderedImage image} and the necessary geographic Information. * * @param name the name of the coverage. * @param renderedImage the image containing the data. * @param envelopeParams the map of boundary parameters. * @param crs the {@link CoordinateReferenceSystem}. * @return the {@link GridCoverage2D coverage}. */ public static GridCoverage2D buildCoverage( String name, RenderedImage renderedImage, HashMap<String, Double> envelopeParams, CoordinateReferenceSystem crs ) { double west = envelopeParams.get(WEST); double south = envelopeParams.get(SOUTH); double east = envelopeParams.get(EAST); double north = envelopeParams.get(NORTH); Envelope2D writeEnvelope = new Envelope2D(crs, west, south, east - west, north - south); GridCoverageFactory factory = CoverageFactoryFinder.getGridCoverageFactory(null); GridCoverage2D coverage2D = factory.create(name, renderedImage, writeEnvelope); return coverage2D; }
Example #27
Source File: CRSPair.java From sis with Apache License 2.0 | 5 votes |
/** * Creates a {@code CRSPair} for the specified source and target CRS. */ CRSPair(final CoordinateReferenceSystem sourceCRS, final CoordinateReferenceSystem targetCRS) { this.sourceCRS = sourceCRS; this.targetCRS = targetCRS; }
Example #28
Source File: RestoreSecurityContextTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
private void checkMarino() throws Exception { CoordinateReferenceSystem crs = beanLayer.getCrs(); Envelope envelope; recorder.clear(); envelope = layerService.getBounds(LAYER_ID, crs, null); junit.framework.Assert.assertEquals(2, envelope.getMinX(), ALLOWANCE); junit.framework.Assert.assertEquals(0, envelope.getMinY(), ALLOWANCE); junit.framework.Assert.assertEquals(7, envelope.getMaxX(), ALLOWANCE); junit.framework.Assert.assertEquals(3, envelope.getMaxY(), ALLOWANCE); }
Example #29
Source File: Las.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
/** * Get a las reader. * * @param lasFile the file to read. * @return the las reader. * @throws Exception if something goes wrong. */ public static ALasReader getReader( File lasFile ) throws Exception { String nameWithoutExtention = FileUtilities.getNameWithoutExtention(lasFile); File prjFile = new File(lasFile.getParentFile(), nameWithoutExtention + ".prj"); CoordinateReferenceSystem crs = null; if (prjFile.exists()) { try { crs = CrsUtilities.readProjectionFile(prjFile.getAbsolutePath(), null); } catch (Exception e) { // try to go on without crs. } } return getReader(lasFile, crs); }
Example #30
Source File: OmsLW04_BankfullWidthAnalyzer.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
@Execute public void process() throws Exception { // Creates the output points hashmap LinkedHashMap<SimpleFeature, double[]> allNetPointsMap = new LinkedHashMap<SimpleFeature, double[]>(); CoordinateReferenceSystem crs = inNetPoints.getBounds().getCoordinateReferenceSystem(); // Insert the points in the final hashmap List<SimpleFeature> netFeatures = FeatureUtilities.featureCollectionToList(inNetPoints); netFeatures.sort(new Comparator<SimpleFeature>(){ public int compare( SimpleFeature o1, SimpleFeature o2 ) { int i1 = ((Number) o1.getAttribute(LWFields.LINKID)).intValue(); int i2 = ((Number) o2.getAttribute(LWFields.LINKID)).intValue(); if (i1 < i2) { return -1; } else if (i1 > i2) { return 1; } return 0; } }); for( SimpleFeature netFeature : netFeatures ) { allNetPointsMap.put(netFeature, new double[NEW_NETWORK_ATTRIBUTES_NUM]); } // Generates supporting variables LinkedHashMap<SimpleFeature, String> problemPointsMap = new LinkedHashMap<SimpleFeature, String>(); LinkedHashMap<SimpleFeature, double[]> validPointsMap = new LinkedHashMap<SimpleFeature, double[]>(); ConcurrentLinkedQueue<Object[]> validPointsLineList = new ConcurrentLinkedQueue<Object[]>(); handleChannelEdited(inBankfull, allNetPointsMap, validPointsMap, problemPointsMap, validPointsLineList); outNetPoints = getNetworkPoints(crs, validPointsMap); outBankfullSections = getWidthLines(crs, validPointsLineList); outProblemPoints = getProblemPoints(crs, problemPointsMap); }