org.locationtech.jts.geom.Coordinate Java Examples

The following examples show how to use org.locationtech.jts.geom.Coordinate. 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: VectorTileEncoderTest.java    From java-vector-tile with 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 #2
Source File: GeometryHullTool.java    From geowave with 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 #3
Source File: SubsetUI.java    From snap-desktop with 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 #4
Source File: SimpleFeatureGenerator.java    From geowave with 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 #5
Source File: TestENU.java    From hortonmachine with 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 #6
Source File: PersistenceEncodingTest.java    From geowave with 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 #7
Source File: VectorTileDecoderTest.java    From java-vector-tile with 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 #8
Source File: OmsGeomorphon.java    From hortonmachine with 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 #9
Source File: RiverSectionsFromDtmExtractor.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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 File: ProfilePoint.java    From hortonmachine with 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 #11
Source File: GeoJSONDecoder.java    From arctic-sea with 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 #12
Source File: JTSTest.java    From sis with 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 #13
Source File: ProduceEqualDistanceGrid.java    From collect-earth with 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 #14
Source File: AccumuloRangeQueryTest.java    From geowave with 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 #15
Source File: GeometryUtil.java    From MeteoInfo with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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 #16
Source File: EnvelopeOrGeometry.java    From arctic-sea with Apache License 2.0 5 votes vote down vote up
public Coordinate getCoordinate() {
    if (this.geometry != null) {
        return this.geometry.getCoordinate();
    } else if (this.envelope != null) {
        return this.envelope.getCoordinate();
    } else {
        return null;
    }
}
 
Example #17
Source File: TPSInterpolator.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #18
Source File: VectorTileEncoderTest.java    From java-vector-tile with Apache License 2.0 5 votes vote down vote up
public void testPolygonCommandsReverse() {
    
    // https://github.com/mapbox/vector-tile-spec/blob/master/2.1/README.md

    // Ex.: MoveTo(3, 6), LineTo(8, 12), LineTo(20, 34), ClosePath
    List<Coordinate> cs = new ArrayList<Coordinate>();
    cs.add(new Coordinate(3, 6));
    cs.add(new Coordinate(8, 12));
    cs.add(new Coordinate(20, 34));
    cs.add(new Coordinate(3, 6));
    Collections.reverse(cs);
    Polygon polygon = gf.createPolygon(cs.toArray(new Coordinate[cs.size()]));

    List<Integer> commands = new VectorTileEncoder(256).commands(polygon);
    assertNotNull(commands);
    // Encoded as: [ 9 6 12 18 10 12 24 44 15 ]
    assertCommand(9, commands, 0);
    assertCommand(6, commands, 1);
    assertCommand(12, commands, 2);
    assertCommand(18, commands, 3);
    assertCommand(10, commands, 4);
    assertCommand(12, commands, 5);
    assertCommand(24, commands, 6);
    assertCommand(44, commands, 7);
    assertCommand(15, commands, 8);
    assertEquals(9, commands.size());

}
 
Example #19
Source File: JTSTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests {@link Geometries#tryMergePolylines(Object, Iterator)}.
 */
@Test
@Override
public void testTryMergePolylines() {
    super.testTryMergePolylines();
    final MultiLineString mp = (MultiLineString) geometry;
    assertEquals("numGeometries", 3, mp.getNumGeometries());
    verifyTwoFirstGeometries(mp);
    assertArrayEquals(new Coordinate[] {
            new Coordinate(13, 11),
            new Coordinate(14, 12),
            new Coordinate(15, 11),
            new Coordinate(13, 10)}, mp.getGeometryN(2).getCoordinates());
}
 
Example #20
Source File: TestVectorReader.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public void testPropertiesReader() throws Exception {

        URL dataUrl = this.getClass().getClassLoader().getResource("example.properties");
        String propertiesPath = new File(dataUrl.toURI()).getAbsolutePath();

        // now read it again
        OmsVectorReader reader = new OmsVectorReader();
        reader.file = propertiesPath;
        reader.process();
        SimpleFeatureCollection readFC = reader.outVector;

        FeatureIterator<SimpleFeature> featureIterator = readFC.features();
        while( featureIterator.hasNext() ) {
            SimpleFeature f = featureIterator.next();

            int id = ((Number) f.getAttribute("id")).intValue();
            Geometry geometry = (Geometry) f.getDefaultGeometry();
            Coordinate coordinate = geometry.getCoordinate();

            if (id == 1) {
                assertEquals(coordinate.x, 0.0);
                assertEquals(coordinate.y, 0.0);
            }
            if (id == 2) {
                assertEquals(coordinate.x, 10.0);
                assertEquals(coordinate.y, 10.0);
            }
            if (id == 3) {
                assertEquals(coordinate.x, 20.0);
                assertEquals(coordinate.y, 20.0);
            }
            if (id == 4) {
                String attribute = f.getAttribute("name").toString();
                assertEquals(attribute, "justin deolivera");
            }
        }

    }
 
Example #21
Source File: SimpleIngestTest.java    From geowave with Apache License 2.0 5 votes vote down vote up
protected static Set<Point> getCalcedPointSet() {
  final Set<Point> calcPoints = new TreeSet<>();
  for (int longitude = -180; longitude <= 180; longitude += 5) {
    for (int latitude = -90; latitude <= 90; latitude += 5) {
      final Point p =
          GeometryUtils.GEOMETRY_FACTORY.createPoint(new Coordinate(longitude, latitude));
      calcPoints.add(p);
    }
  }
  return calcPoints;
}
 
Example #22
Source File: RasterUtils.java    From geowave with Apache License 2.0 5 votes vote down vote up
public static Geometry getFootprint(
    final ReferencedEnvelope projectedReferenceEnvelope,
    final GridCoverage gridCoverage) {
  try {
    final Envelope sampleEnvelope = gridCoverage.getEnvelope();
    final double avgSpan =
        (projectedReferenceEnvelope.getSpan(0) + projectedReferenceEnvelope.getSpan(1)) / 2;
    final MathTransform gridCrsToWorldCrs =
        CRS.findMathTransform(
            gridCoverage.getCoordinateReferenceSystem(),
            projectedReferenceEnvelope.getCoordinateReferenceSystem(),
            true);
    final Coordinate[] polyCoords =
        getWorldCoordinates(
            sampleEnvelope.getMinimum(0),
            sampleEnvelope.getMinimum(1),
            sampleEnvelope.getMaximum(0),
            sampleEnvelope.getMaximum(1),
            gridCrsToWorldCrs.isIdentity() ? 2
                : (int) Math.min(
                    Math.max((avgSpan * MIN_SEGMENTS) / SIMPLIFICATION_MAX_DEGREES, MIN_SEGMENTS),
                    MAX_SEGMENTS),
            gridCrsToWorldCrs);
    final Polygon poly = new GeometryFactory().createPolygon(polyCoords);
    if (polyCoords.length > MAX_VERTICES_BEFORE_SIMPLIFICATION) {
      final Geometry retVal = DouglasPeuckerSimplifier.simplify(poly, SIMPLIFICATION_MAX_DEGREES);
      if (retVal.isEmpty()) {
        return poly;
      }
      return retVal;
    } else {
      return poly;
    }
  } catch (MismatchedDimensionException | TransformException | FactoryException e1) {
    LOGGER.warn("Unable to calculate grid coverage footprint", e1);
  }
  return null;
}
 
Example #23
Source File: GeoUtils.java    From elasticsearch-plugin-geoshape with MIT License 5 votes vote down vote up
public static List<GeoPoint> getBboxFromCoords(Coordinate[] coords) {
    GeoPoint topLeft = new GeoPoint(
            org.elasticsearch.common.geo.GeoUtils.normalizeLat(coords[0].y),
            org.elasticsearch.common.geo.GeoUtils.normalizeLon(coords[0].x)
    );
    GeoPoint bottomRight = new GeoPoint(
            org.elasticsearch.common.geo.GeoUtils.normalizeLat(coords[2].y),
            org.elasticsearch.common.geo.GeoUtils.normalizeLon(coords[2].x)
    );
    return Arrays.asList(topLeft, bottomRight);
}
 
Example #24
Source File: WFSBoundedSpatialQueryTest.java    From geowave with Apache License 2.0 5 votes vote down vote up
public void populate() throws IOException, CQLException, ParseException {
  final Transaction transaction1 = new DefaultTransaction();

  final FeatureWriter<SimpleFeatureType, SimpleFeature> writer =
      dataStore.getFeatureWriter(type.getTypeName(), transaction1);
  assertFalse(writer.hasNext());
  SimpleFeature newFeature = writer.next();
  newFeature.setAttribute("pop", Long.valueOf(100));
  newFeature.setAttribute("pid", UUID.randomUUID().toString());
  newFeature.setAttribute("when", DateUtilities.parseISO("2005-05-19T20:32:56Z"));
  newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(43.454, 28.232)));
  writer.write();

  newFeature = writer.next();
  newFeature.setAttribute("pop", Long.valueOf(100));
  newFeature.setAttribute("pid", UUID.randomUUID().toString());
  newFeature.setAttribute("when", DateUtilities.parseISO("2005-05-18T20:32:56Z"));
  newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(43.454, 27.232)));
  writer.write();

  newFeature = writer.next();
  newFeature.setAttribute("pop", Long.valueOf(100));
  newFeature.setAttribute("pid", UUID.randomUUID().toString());
  newFeature.setAttribute("when", DateUtilities.parseISO("2005-05-17T20:32:56Z"));
  newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(43.454, 28.232)));
  writer.write();
  writer.close();
  transaction1.commit();
  transaction1.close();
}
 
Example #25
Source File: ShapefilesFolderLayer.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Coordinate getCenter() {
    if (bounds != null)
        return bounds.centre();
    else
        return new Coordinate(0, 0);
}
 
Example #26
Source File: ElasticParserUtilTest.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testGeoPointAsIntegerProperties() {
    final int lat = rand.nextInt(180) - 90;
    final int lon = rand.nextInt(360) - 180;
    properties.put("lat", lat);
    properties.put("lon", lon);
    final Geometry geometry = parserUtil.createGeometry(properties);
    assertTrue(geometry.equals(geometryFactory.createPoint(new Coordinate(lon, lat))));
}
 
Example #27
Source File: ElasticParserUtilTest.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testGeoPointAsDoubleProperties() {
    final double lat = rand.nextDouble() * 90 - 90;
    final double lon = rand.nextDouble() * 180 - 180;
    properties.put("lat", lat);
    properties.put("lon", lon);
    final Geometry geometry = parserUtil.createGeometry(properties);
    assertTrue(geometry.equals(geometryFactory.createPoint(new Coordinate(lon, lat))));
}
 
Example #28
Source File: FeatureLayerType.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Object convertDomToValue(DomElement parentElement, Object value) throws ConversionException,
        ValidationException {
    org.locationtech.jts.geom.GeometryFactory gf = new org.locationtech.jts.geom.GeometryFactory();
    final DefaultDomConverter domConverter = new DefaultDomConverter(Coordinate.class);
    final DomElement[] children = parentElement.getChildren("coordinate");
    List<Coordinate> coordList = new ArrayList<Coordinate>();
    for (DomElement child : children) {
        final Coordinate coordinate = (Coordinate) domConverter.convertDomToValue(child, null);
        coordList.add(coordinate);
    }
    return gf.createPolygon(gf.createLinearRing(coordList.toArray(new Coordinate[coordList.size()])), null);
}
 
Example #29
Source File: GPXConsumer.java    From geowave with Apache License 2.0 5 votes vote down vote up
public List<Coordinate> buildCoordinates() {
  if (isCoordinate()) {
    return Arrays.asList(getCoordinate());
  }
  final ArrayList<Coordinate> coords = new ArrayList<>();
  for (int i = 0; (children != null) && (i < children.size()); i++) {
    coords.addAll(children.get(i).buildCoordinates());
  }
  return coords;
}
 
Example #30
Source File: MercatorUtils.java    From hortonmachine with 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;
}