Java Code Examples for org.locationtech.jts.geom.Coordinate

The following examples show how to use org.locationtech.jts.geom.Coordinate. These examples are extracted from open source projects. 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 Project: snap-desktop   Source File: SubsetUI.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void getGeoRegion() {
    geoRegion = null;
    geoText.setText("");
    if (geoCoordRadio.isSelected()) {
        final GeoPos[] selectionBox = worldMapUI.getSelectionBox();
        if (selectionBox != null) {
            final Coordinate[] coords = new Coordinate[selectionBox.length + 1];
            for (int i = 0; i < selectionBox.length; ++i) {
                coords[i] = new Coordinate(selectionBox[i].getLon(), selectionBox[i].getLat());
            }
            coords[selectionBox.length] = new Coordinate(selectionBox[0].getLon(), selectionBox[0].getLat());

            final GeometryFactory geometryFactory = new GeometryFactory();
            final LinearRing linearRing = geometryFactory.createLinearRing(coords);

            geoRegion = geometryFactory.createPolygon(linearRing, null);
            geoText.setText(geoRegion.toText());
        }
    }
}
 
Example 2
Source Project: hortonmachine   Source File: TestENU.java    License: GNU General Public License v3.0 6 votes vote down vote up
public void testWithGeotools() throws MatrixException {
    Coordinate c1 = new Coordinate(11, 46, 0);
    Coordinate c2 = new Coordinate(11.001, 46.001, 0);

    GeodeticCalculator gc = new GeodeticCalculator(DefaultGeographicCRS.WGS84);
    gc.setStartingGeographicPoint(c1.x, c1.y);
    gc.setDestinationGeographicPoint(c2.x, c2.y);
    double orthodromicDistance = gc.getOrthodromicDistance();

    ENU enu = new ENU(c1);
    Coordinate ce1 = enu.wgs84ToEnu(c1);
    Coordinate ce2 = enu.wgs84ToEnu(c2);

    double distance = ce1.distance(ce2);
    assertTrue(isDeltaOk(orthodromicDistance, distance));
    
    Coordinate c1Back = enu.enuToWgs84(ce1);
    Coordinate c2Back = enu.enuToWgs84(ce2);
    
    assertEquals(0, c1.distance(c1Back), 0.000001);
    assertEquals(0, c2.distance(c2Back), 0.000001);
    
}
 
Example 3
Source Project: geowave   Source File: GeometryHullTool.java    License: Apache License 2.0 6 votes vote down vote up
private static boolean isCandidateCloserToAnotherEdge(
    final double distanceToBeat,
    final Edge selectedEdgeToBeat,
    final Collection<Edge> edges,
    final Coordinate selectedCandidate) {
  for (final Edge edge : edges) {
    if (selectedEdgeToBeat.equals(edge)) {
      continue;
    }
    final double dist = calcDistance(edge.start, edge.end, selectedCandidate);
    if ((dist >= 0.0) && (dist < distanceToBeat)) {
      return true;
    }
  }
  return false;
}
 
Example 4
Source Project: geowave   Source File: PersistenceEncodingTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testPoly() {
  final GeoObjDataAdapter adapter =
      new GeoObjDataAdapter(NATIVE_FIELD_HANDLER_LIST, COMMON_FIELD_HANDLER_LIST);
  final GeoObj entry =
      new GeoObj(
          factory.createLineString(
              new Coordinate[] {
                  new Coordinate(43.444, 28.232),
                  new Coordinate(43.454, 28.242),
                  new Coordinate(43.444, 28.252),
                  new Coordinate(43.444, 28.232),}),
          start,
          end,
          "g1");
  final List<byte[]> ids =
      adapter.encode(entry, model).getInsertionIds(index).getCompositeInsertionIds();
  assertEquals(18, ids.size());
}
 
Example 5
Source Project: java-vector-tile   Source File: VectorTileDecoderTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testMultiPoint() throws IOException {
    Coordinate c1 = new Coordinate(2, 3);
    Coordinate c2 = new Coordinate(3, 4);
    Geometry geometry = gf.createMultiPointFromCoords(new Coordinate[] { c1, c2 });
    Map<String, Object> attributes = new HashMap<String, Object>();
    attributes.put("hello", 123);
    String layerName = "layer";

    VectorTileEncoder e = new VectorTileEncoder(512);
    e.addFeature(layerName, attributes, geometry);
    byte[] encoded = e.encode();

    VectorTileDecoder d = new VectorTileDecoder();
    assertEquals(1, d.decode(encoded).getLayerNames().size());
    assertEquals(layerName, d.decode(encoded).getLayerNames().iterator().next());

    assertEquals(attributes, d.decode(encoded, layerName).asList().get(0).getAttributes());
    assertEquals(geometry, d.decode(encoded, layerName).asList().get(0).getGeometry());
}
 
Example 6
/**
 * Computes the smallest convex <code>Polygon</code> that contains all the
 * points
 *
 * @param x X array
 * @param y Y array
 * @return PolygonShape
 */
public static PolygonShape convexHull(Array x, Array y) {
    int n = (int) x.getSize();
    List<Geometry> geos = new ArrayList<>();
    GeometryFactory factory = new GeometryFactory();
    IndexIterator xIter = x.getIndexIterator();
    IndexIterator yIter = y.getIndexIterator();
    double xx, yy;
    while(xIter.hasNext()) {
        xx = xIter.getDoubleNext();
        yy = yIter.getDoubleNext();
        if (!Double.isNaN(xx) && !Double.isNaN(yy)) {
            Coordinate c = new Coordinate(xx, yy);
            geos.add(factory.createPoint(c));
        }
    }
    Geometry gs = factory.createGeometryCollection(geos.toArray(new Geometry[geos.size()]));
    Geometry ch = gs.convexHull();
    return new PolygonShape(ch);
}
 
Example 7
Source Project: java-vector-tile   Source File: VectorTileEncoderTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testMultiPoint() {

        List<Coordinate> cs = new ArrayList<Coordinate>();
        cs.add(new Coordinate(5, 7));
        cs.add(new Coordinate(3, 2));

        List<Integer> commands = new VectorTileEncoder(256).commands(cs.toArray(new Coordinate[cs.size()]), false,
                true);
        assertNotNull(commands);

        assertCommand(17, commands, 0);
        assertCommand(10, commands, 1);
        assertCommand(14, commands, 2);
        assertCommand(3, commands, 3);
        assertCommand(9, commands, 4);
        assertEquals(5, commands.size());

    }
 
Example 8
Source Project: collect-earth   Source File: ProduceEqualDistanceGrid.java    License: MIT License 6 votes vote down vote up
public static void main(String[] args) {

		Coordinate northWest = new Coordinate( -100, 80);
		Coordinate	 southEast = new Coordinate( 100, -80);
		Float distanceInMeters = 100000f;

		ProduceEqualDistanceGrid equalDistanceGrid = new ProduceEqualDistanceGrid();
		try {

			File csvFile = equalDistanceGrid.getEqualDistanceGridInMeters( northWest, southEast, distanceInMeters );			
			FileUtils.copyFile(csvFile, new File("equalDistance.csv") );
			System.out.println( csvFile.getAbsolutePath() );

		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			System.exit(0);
		}
	}
 
Example 9
/**
 * Extract a {@link RiverPoint}.
 * 
 * @param riverLine the geometry of the main river.
 * @param elevIter the elevation raster.
 * @param gridGeometry the raster geometry.
 * @param progressiveDistance the progressive distance along the main river.
 * @param ks the KS for the section.
 * @param leftPoint the left point of the section.
 * @param rightPoint the right point of the section.
 * @return the created {@link RiverPoint}.
 * @throws TransformException
 */
private RiverPoint getNetworkPoint( LineString riverLine, RandomIter elevIter, GridGeometry2D gridGeometry,
        double progressiveDistance, Double ks, Coordinate leftPoint, Coordinate rightPoint ) throws TransformException {
    List<ProfilePoint> sectionPoints = CoverageUtilities.doProfile(elevIter, gridGeometry, rightPoint, leftPoint);
    List<Coordinate> coordinate3dList = new ArrayList<Coordinate>();
    for( ProfilePoint sectionPoint : sectionPoints ) {
        Coordinate position = sectionPoint.getPosition();
        position.z = sectionPoint.getElevation();
        coordinate3dList.add(position);
    }
    LineString sectionLine3d = gf.createLineString(coordinate3dList.toArray(new Coordinate[0]));
    Geometry crossPoint = sectionLine3d.intersection(riverLine);
    Coordinate coordinate = crossPoint.getCoordinate();
    if (coordinate == null) {
        return null;
    }
    int[] colRow = CoverageUtilities.colRowFromCoordinate(coordinate, gridGeometry, null);
    double elev = elevIter.getSampleDouble(colRow[0], colRow[1], 0);
    coordinate.z = elev;
    RiverPoint netPoint = new RiverPoint(coordinate, progressiveDistance, sectionLine3d, ks);
    return netPoint;
}
 
Example 10
Source Project: hortonmachine   Source File: OmsGeomorphon.java    License: GNU General Public License v3.0 6 votes vote down vote up
private static void calculateCount( RandomIter elevIter, GridGeometry2D gridGeometry, int[] plusCount, int[] minusCount,
        double elevation, Coordinate center, Coordinate otherCoordinate, double angleThreshold ) throws TransformException {
    List<ProfilePoint> profile = CoverageUtilities.doProfile(elevIter, gridGeometry, center, otherCoordinate);
    double[] lastVisiblePointData = ProfilePoint.getLastVisiblePointData(profile);

    if (lastVisiblePointData != null) {
        double zenithAngle = lastVisiblePointData[4];
        double nadirAngle = 180 - lastVisiblePointData[9];

        double diff = nadirAngle - zenithAngle;
        int zeroCount = 0;
        if (diff > angleThreshold) {
            plusCount[0] = plusCount[0] + 1;
        } else if (diff < -angleThreshold) {
            minusCount[0] = minusCount[0] + 1;
        } else if (abs(diff) < angleThreshold) {
            zeroCount++;
        } else {
            throw new IllegalArgumentException();
        }
    }
}
 
Example 11
Source Project: geowave   Source File: SimpleFeatureGenerator.java    License: Apache License 2.0 6 votes vote down vote up
private static Geometry getGeometry(
    final OSMUnion osm,
    final OsmProvider provider,
    final FeatureDefinition fd) {
  switch (osm.OsmType) {
    case NODE: {
      return GeometryUtils.GEOMETRY_FACTORY.createPoint(
          new Coordinate(osm.Longitude, osm.Lattitude));
    }
    case RELATION: {
      return provider.processRelation(osm, fd);
    }
    case WAY: {
      return provider.processWay(osm, fd);
    }
  }
  return null;
}
 
Example 12
Source Project: hortonmachine   Source File: ProfilePoint.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean equals( Object obj ) {
    if (this == obj)
        return true;
    if (obj == null)
        return false;
    if (getClass() != obj.getClass())
        return false;
    ProfilePoint other = (ProfilePoint) obj;

    /*
     * the progressive point is equal if the elevation, x, y are equal.
     * This can be is used to find intersecting profiles.
     */
    Coordinate otherPosition = other.position;
    if (NumericsUtilities.dEq(elevation, other.elevation) && NumericsUtilities.dEq(position.x, otherPosition.x)
            && NumericsUtilities.dEq(position.y, otherPosition.y)) {
        return true;
    } else {
        return false;
    }
}
 
Example 13
Source Project: arctic-sea   Source File: GeoJSONDecoder.java    License: Apache License 2.0 6 votes vote down vote up
protected Coordinate decodeCoordinate(JsonNode node)
        throws GeoJSONDecodingException {
    if (!node.isArray()) {
        throw new GeoJSONDecodingException(EXPECTED_ARRAY);
    }
    final int dim = node.size();
    if (dim < DIM_2D) {
        throw new GeoJSONDecodingException("coordinates may have at least 2 dimensions");
    }
    if (dim > DIM_3D) {
        throw new GeoJSONDecodingException("coordinates may have at most 3 dimensions");
    }
    final Coordinate coordinate = new Coordinate();
    for (int i = 0; i < dim; ++i) {
        if (node.get(i).isNumber()) {
            coordinate.setOrdinate(i, node.get(i).doubleValue());
        } else {
            throw new GeoJSONDecodingException("coordinate index " + i + " has to be a number");
        }
    }
    return coordinate;
}
 
Example 14
Source Project: sis   Source File: JTSTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Tests {@link JTS#getCoordinateReferenceSystem(Geometry)}.
 *
 * @throws FactoryException if an EPSG code can not be resolved.
 */
@Test
public void testGetCoordinateReferenceSystem() throws FactoryException {
    final GeometryFactory factory = new GeometryFactory();
    final Geometry geometry = factory.createPoint(new Coordinate(5, 6));

    CoordinateReferenceSystem crs = JTS.getCoordinateReferenceSystem(geometry);
    assertNull(crs);
    /*
     * Test CRS as user data.
     */
    geometry.setUserData(CommonCRS.ED50.geographic());
    assertEquals(CommonCRS.ED50.geographic(), JTS.getCoordinateReferenceSystem(geometry));
    /*
     * Test CRS as map value.
     */
    geometry.setUserData(Collections.singletonMap(JTS.CRS_KEY, CommonCRS.NAD83.geographic()));
    assertEquals(CommonCRS.NAD83.geographic(), JTS.getCoordinateReferenceSystem(geometry));
    /*
     * Test CRS as srid.
     */
    geometry.setUserData(null);
    geometry.setSRID(4326);
    assertEquals(CommonCRS.WGS84.geographic(), JTS.getCoordinateReferenceSystem(geometry));
}
 
Example 15
Source Project: geowave   Source File: AccumuloRangeQueryTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testIntersection() {
  final Geometry testGeo =
      factory.createPolygon(
          new Coordinate[] {
              new Coordinate(1.0249, 1.0319),
              new Coordinate(1.0261, 1.0319),
              new Coordinate(1.0261, 1.0323),
              new Coordinate(1.0249, 1.0319)});
  final QueryConstraints intersectQuery = new ExplicitSpatialQuery(testGeo);
  Assert.assertTrue(testdata.geom.intersects(testGeo));
  final CloseableIterator<TestGeometry> resultOfIntersect =
      (CloseableIterator) mockDataStore.query(
          QueryBuilder.newBuilder().addTypeName(adapter.getTypeName()).indexName(
              index.getName()).constraints(intersectQuery).build());
  Assert.assertTrue(resultOfIntersect.hasNext());
}
 
Example 16
Source Project: geowave   Source File: NNMapReduceTest.java    License: Apache License 2.0 5 votes vote down vote up
private SimpleFeature createTestFeature(final Coordinate coord) {
  return AnalyticFeature.createGeometryFeature(
      ftype,
      "b1",
      UUID.randomUUID().toString(),
      "fred",
      "NA",
      20.30203,
      factory.createPoint(coord),
      new String[] {"extra1"},
      new double[] {0.022},
      1,
      1,
      0);
}
 
Example 17
Source Project: hortonmachine   Source File: Raster.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get world position from col, row.
 * 
 * @param col
 * @param row
 * @return the [x, y] position or <code>null</code> if outside the bounds.
 */
public double[] positionAt( int col, int row ) {
    if (isInRaster(col, row)) {
        GridGeometry2D gridGeometry = getGridGeometry();
        Coordinate coordinate = CoverageUtilities.coordinateFromColRow(col, row, gridGeometry);
        return new double[]{coordinate.x, coordinate.y};
    }
    return null;
}
 
Example 18
/**
 * Fill O submatrix (<a href="http://elonen.iki.fi/code/tpsdemo/index.html"> see more here</a>)
 */
private void fillOsubMatrix( Coordinate[] controlPoints, GeneralMatrix L ) {
    int controlPointsNum = controlPoints.length;
    for( int i = controlPointsNum; i < (controlPointsNum + 3); i++ ) {
        for( int j = controlPointsNum; j < (controlPointsNum + 3); j++ ) {
            L.setElement(i, j, 0);
        }
    }
}
 
Example 19
private String handleCoordinates( List<SimpleFeature> junctionsList, List<SimpleFeature> reservoirsList,
        List<SimpleFeature> tanksList ) throws IOException {
    ArrayList<SimpleFeature> nodesList = new ArrayList<SimpleFeature>();
    nodesList.addAll(junctionsList);
    nodesList.addAll(reservoirsList);
    nodesList.addAll(tanksList);

    StringBuilder sbJunctionsCoords = new StringBuilder();
    sbJunctionsCoords.append("\n\n[COORDINATES]\n");
    sbJunctionsCoords.append(";NODE").append(SPACER);
    sbJunctionsCoords.append("XCOORD").append(SPACER);
    sbJunctionsCoords.append("YCOORD").append(NL);

    for( SimpleFeature node : nodesList ) {
        Geometry geometry = (Geometry) node.getDefaultGeometry();
        Coordinate coordinate = geometry.getCoordinate();

        // [COORDINATES]
        Object attribute = getAttribute(node, Junctions.ID.getAttributeName());
        sbJunctionsCoords.append(attribute.toString());
        sbJunctionsCoords.append(SPACER);
        sbJunctionsCoords.append(coordinate.x);
        sbJunctionsCoords.append(SPACER);
        sbJunctionsCoords.append(coordinate.y);
        sbJunctionsCoords.append(NL);
    }

    sbJunctionsCoords.append("\n\n");
    return sbJunctionsCoords.toString();
}
 
Example 20
Source Project: hortonmachine   Source File: Bspline.java    License: GNU General Public License v3.0 5 votes vote down vote up
public List<Coordinate> getInterpolated() {
    List<Coordinate> interpolatedCoordinates = new ArrayList<Coordinate>();
    Coordinate q = p(2, 0);
    interpolatedCoordinates.add(q);
    for( int i = 2; i < pts.size() - 1; i++ ) {
        for( int j = 1; j <= STEPS; j++ ) {
            q = p(i, j / (double) STEPS);
            interpolatedCoordinates.add(q);
        }
    }
    return interpolatedCoordinates;
}
 
Example 21
Source Project: MeteoInfo   Source File: Polygon.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * To geometry
 *
 * @param factory GeometryFactory
 * @return Geometry
 */
public Geometry toGeometry(GeometryFactory factory) {
    PointD p;
    Coordinate[] cs = new Coordinate[_outLine.size()];
    for (int i = 0; i < cs.length; i++) {
        p = _outLine.get(i);
        cs[i] = new Coordinate(p.X, p.Y);
    }
    if (cs[0].x != cs[cs.length -1].x){
        cs = (Coordinate[])DataConvert.resizeArray(cs, cs.length + 1);
        cs[cs.length - 1] = new Coordinate(cs[0].x, cs[1].y);
    }
    LinearRing shell = factory.createLinearRing(cs);
    LinearRing[] holes = new LinearRing[this._holeLines.size()];
    int n;
    boolean isclose;
    for (int j = 0; j < holes.length; j++) {
        List<? extends PointD> hole = this._holeLines.get(j);
        n = hole.size();
        isclose = true;
        if (n == 3) {
            n = 4;
            isclose = false;
        }
        cs = new Coordinate[n];
        for (int i = 0; i < hole.size(); i++) {
            p = hole.get(i);
            cs[i] = new Coordinate(p.X, p.Y);
        }      
        if (!isclose){
            cs[n - 1] = new Coordinate(hole.get(0).X, hole.get(0).Y);
        }
        holes[j] = factory.createLinearRing(cs);
    }
    return factory.createPolygon(shell, holes);
}
 
Example 22
@Override
protected Layer createLayer(LayerType layerType) throws Exception {

    final PropertySet configuration = layerType.createLayerConfig(null);

    final URL shapefileUrl = getClass().getResource("bundeslaender.shp");
    configuration.setValue(FeatureLayerType.PROPERTY_NAME_FEATURE_COLLECTION_URL, shapefileUrl);
    configuration.setValue(FeatureLayerType.PROPERTY_NAME_FEATURE_COLLECTION_CRS, DefaultGeographicCRS.WGS84);
    final Coordinate[] coordinates = {
            new Coordinate(-10, 50),
            new Coordinate(+10, 50),
            new Coordinate(+10, 30),
            new Coordinate(-10, 30),
            new Coordinate(-10, 50)
    };
    final GeometryFactory geometryFactory = new GeometryFactory();
    final LinearRing ring = geometryFactory.createLinearRing(coordinates);
    final Polygon clipGeometry = geometryFactory.createPolygon(ring, new LinearRing[0]);
    configuration.setValue(FeatureLayerType.PROPERTY_NAME_FEATURE_COLLECTION_CLIP_GEOMETRY, clipGeometry);
    configuration.setValue(FeatureLayerType.PROPERTY_NAME_SLD_STYLE, createStyle());
    FeatureCollection<SimpleFeatureType, SimpleFeature> fc;
    try {
        fc = FeatureUtils.createFeatureCollection(
                shapefileUrl, DefaultGeographicCRS.WGS84, clipGeometry);
    } catch (IOException e) {
        throw new IllegalArgumentException(e);
    }
    return new FeatureLayer(layerType, fc, configuration);
}
 
Example 23
@Override
public Coordinate getCenter() {
    try {
        ReferencedEnvelope bounds = getfeatureCollection().getBounds();
        return bounds.centre();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return new Coordinate(0, 0);
}
 
Example 24
Source Project: hortonmachine   Source File: Bezier.java    License: GNU General Public License v3.0 5 votes vote down vote up
public List<Coordinate> getInterpolated() {
    List<Coordinate> coordList = new ArrayList<Coordinate>();
    Coordinate q = p(0, 0);
    coordList.add(q);
    for( int i = 0; i < pts.size() - 3; i += 3 ) {
        for( int j = 1; j <= STEPS; j++ ) {
            q = p(i, j / (double) STEPS);
            coordList.add(q);
        }
    }
    return coordList;
}
 
Example 25
Source Project: datawave   Source File: GeoFunctionsDescriptor.java    License: Apache License 2.0 5 votes vote down vote up
private Polygon createCircle(double lon, double lat, double radius) {
    GeometricShapeFactory shapeFactory = new GeometricShapeFactory();
    shapeFactory.setNumPoints(NUM_CIRCLE_POINTS);
    shapeFactory.setCentre(new Coordinate(lon, lat));
    shapeFactory.setSize(radius * 2);
    return shapeFactory.createCircle();
}
 
Example 26
public void testVectorFieldRounder() throws Exception {

        SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
        b.setName("test");
        b.setCRS(DefaultGeographicCRS.WGS84);
        b.add("the_geom", Point.class);
        b.add("area", Double.class);

        DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
        SimpleFeatureType type = b.buildFeatureType();
        SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
        Point point = GeometryUtilities.gf().createPoint(new Coordinate(0, 0));
        Object[] values = new Object[]{point, 123.456789};
        builder.addAll(values);
        SimpleFeature feature = builder.buildFeature(type.getTypeName() + ".0");
        newCollection.add(feature);

        OmsVectorFieldRounder rounder = new OmsVectorFieldRounder();
        rounder.inVector = newCollection;
        rounder.fRound = "area";
        rounder.pPattern = ".##";
        rounder.process();
        SimpleFeatureCollection outFeatures = rounder.outVector;

        SimpleFeature f = FeatureUtilities.featureCollectionToList(outFeatures).get(0);
        String areaStr = f.getAttribute("area").toString();

        assertTrue(areaStr.equals("123.46"));
    }
 
Example 27
Source Project: crate   Source File: GeoJSONUtils.java    License: Apache License 2.0 5 votes vote down vote up
double[][] toArray(Coordinate[] coordinates) {
    double[][] array = new double[coordinates.length][];
    for (int i = 0; i < coordinates.length; i++) {
        array[i] = toArray(coordinates[i]);
    }
    return array;
}
 
Example 28
Source Project: hortonmachine   Source File: MercatorUtils.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static Envelope convert3857To4326( Envelope envelope3857 ) {
    Coordinate ll3857 = new Coordinate(envelope3857.getMinX(), envelope3857.getMinY());
    Coordinate ur3857 = new Coordinate(envelope3857.getMaxX(), envelope3857.getMaxY());

    Coordinate ll4326 = convert3857To4326(ll3857);
    Coordinate ur4326 = convert3857To4326(ur3857);

    Envelope env4326 = new Envelope(ll4326, ur4326);
    return env4326;
}
 
Example 29
Source Project: hortonmachine   Source File: TinHandler.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a {@link SimpleFeatureCollection FeatureCollection} from the current tin triangles
 * with information about the vertexes elevation.
 * 
 * @return the feature collection of the tin.
 */
public SimpleFeatureCollection toFeatureCollection() {
    checkTinGeometries();
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName("triangle");
    b.setCRS(crs);

    DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
    b.add("the_geom", Polygon.class);
    b.add("elev0", Double.class);
    b.add("elev1", Double.class);
    b.add("elev2", Double.class);
    SimpleFeatureType type = b.buildFeatureType();
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
    for( Geometry g : tinGeometries ) {
        Coordinate[] coordinates = g.getCoordinates();

        Object[] values;
        int windingRule = GeometryUtilities.getTriangleWindingRule(coordinates[0], coordinates[1], coordinates[2]);
        if (windingRule > 0) {
            // need to reverse the triangle
            values = new Object[]{g, coordinates[0].z, coordinates[2].z, coordinates[1].z};
        } else {
            values = new Object[]{g, coordinates[0].z, coordinates[1].z, coordinates[2].z};
        }

        builder.addAll(values);
        SimpleFeature feature = builder.buildFeature(null);
        newCollection.add(feature);
    }
    return newCollection;
}
 
Example 30
/**
 * Fill L submatrix (<a href="http://elonen.iki.fi/code/tpsdemo/index.html"> see more here</a>)
 */
private void fillPsubMatrix( Coordinate[] controlPoints, GeneralMatrix L ) {
    int controlPointsNum = controlPoints.length;
    for( int i = 0; i < controlPointsNum; i++ ) {
        L.setElement(i, i, 0);

        L.setElement(i, controlPointsNum + 0, 1);
        L.setElement(i, controlPointsNum + 1, controlPoints[i].x);
        L.setElement(i, controlPointsNum + 2, controlPoints[i].y);

        L.setElement(controlPointsNum + 0, i, 1);
        L.setElement(controlPointsNum + 1, i, controlPoints[i].x);
        L.setElement(controlPointsNum + 2, i, controlPoints[i].y);
    }
}