Java Code Examples for com.vividsolutions.jts.geom.GeometryFactory#createPoint()

The following examples show how to use com.vividsolutions.jts.geom.GeometryFactory#createPoint() . 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: GeoServiceTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testCreateCircle() throws Exception {
	Geometry geometry;
	GeometryFactory factory = new GeometryFactory(new PrecisionModel(), 4326);
	Point point = factory.createPoint(new Coordinate(0, 0));
	Point inside = factory.createPoint(new Coordinate(9.5, 0));
	Point insideFine = factory.createPoint(new Coordinate(6.8, 6.8));
	Point outsideAll = factory.createPoint(new Coordinate(9, 5));

	geometry = geoService.createCircle(point, 10, 4);
	Assert.assertEquals(5, geometry.getCoordinates().length);
	Assert.assertTrue(geometry.contains(inside));
	Assert.assertFalse(geometry.contains(insideFine));
	Assert.assertFalse(geometry.contains(outsideAll));

	geometry = geoService.createCircle(point, 10, 16);
	Assert.assertEquals(17, geometry.getCoordinates().length);
	Assert.assertTrue(geometry.contains(inside));
	Assert.assertTrue(geometry.contains(insideFine));
	Assert.assertFalse(geometry.contains(outsideAll));
}
 
Example 2
Source File: StyleConverterServiceImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
private Geometry toSimpleGeometry(GeometryFactory factory, AbstractGeometryInfo geom) throws LayerException {
	Geometry geometry = null;
	if (geom instanceof PointTypeInfo) {
		PointTypeInfo point = (PointTypeInfo) geom;
		if (point.ifCoord()) {
			geometry = factory.createPoint(getCoordinates(Collections.singletonList(point.getCoord()))[0]);
		} else if (point.ifCoordinates()) {
			geometry = factory.createPoint(getCoordinates(point.getCoordinates())[0]);
		}
	} else if (geom instanceof LineStringTypeInfo) {
		LineStringTypeInfo linestring = (LineStringTypeInfo) geom;
		if (linestring.ifCoordList()) {
			geometry = factory.createLineString(getCoordinates(linestring.getCoordList()));
		} else if (linestring.ifCoordinates()) {
			geometry = factory.createLineString(getCoordinates(linestring.getCoordinates()));
		}
	} else if (geom instanceof PolygonTypeInfo) {
		PolygonTypeInfo polygon = (PolygonTypeInfo) geom;
		OuterBoundaryIsInfo outer = polygon.getOuterBoundaryIs();
		LinearRing shell = toLinearRing(factory, outer.getLinearRing());
		if (polygon.getInnerBoundaryIList() == null) {
			geometry = factory.createPolygon(shell, null);
		} else {
			LinearRing[] holes = new LinearRing[polygon.getInnerBoundaryIList().size()];
			int i = 0;
			for (InnerBoundaryIsInfo inner : polygon.getInnerBoundaryIList()) {
				holes[i++] = toLinearRing(factory, inner.getLinearRing());
			}
			geometry = factory.createPolygon(shell, holes);
		}
	}
	return geometry;
}
 
Example 3
Source File: CompressionSMSListener.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected Geometry convertGeoPointToGeometry( GeoPoint coordinates )
{
    if ( coordinates == null )
    {
        return null;
    }

    GeometryFactory gf = new GeometryFactory();
    com.vividsolutions.jts.geom.Coordinate co = new com.vividsolutions.jts.geom.Coordinate(
        coordinates.getLongitude(), coordinates.getLatitude() );

    return gf.createPoint( co );
}
 
Example 4
Source File: GeoLatLon.java    From sql-layer with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void doEvaluate(TExecutionContext context, LazyList<? extends ValueSource> inputs, ValueTarget output) {
    ValueSource input0 = inputs.get(0);
    ValueSource input1 = inputs.get(1);

    GeometryFactory factory = (GeometryFactory)context.preptimeObjectAt(FACTORY_CONTEXT_POS);
    double lat = doubleInRange(TBigDecimal.getWrapper(input0, input0.getType()), MIN_LAT, MAX_LAT);
    double lon = doubleInRange(TBigDecimal.getWrapper(input1, input1.getType()), MIN_LON, MAX_LON);
    Geometry geometry = factory.createPoint(new Coordinate(lat, lon));
    output.putObject(geometry);
}
 
Example 5
Source File: GeoFencingAPI.java    From google-geoEngine with Apache License 2.0 5 votes vote down vote up
/**
 * Endpoint for finding the fences a certain point is in.
 */@ApiMethod(name = "point", httpMethod = "get", path = "point")
public ArrayList < MyFence > queryPoint(@Named("group") String group, @Named("lng") double lng, @Named("lat") double lat) {
    ArrayList < MyFence > fences = new ArrayList < MyFence > ();

    //Get the Index from Memcache.
    MemcacheService syncCache = MemcacheServiceFactory.getMemcacheService();
    GeometryFactory gf = new GeometryFactory();
    STRtree index = (STRtree) syncCache.get(group); // read from cache
    if (index != null) {
        Coordinate coord = new Coordinate(lng, lat);
        Point point = gf.createPoint(coord);
        List < MyPolygon > items = index.query(point.getEnvelopeInternal());
        if (!items.isEmpty()) {
            for (MyPolygon poly: items) {
                if (poly.contains(point)) {
                    long id = poly.getID();
                    MyFence newFence = new MyFence();
                    newFence.setId(id);
                    fences.add(newFence);
                }
            }
        }
    } else {
        try {
            MyIndex.buildIndex(group);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return fences;
}
 
Example 6
Source File: ShapeFile.java    From tutorials with MIT License 5 votes vote down vote up
private static Function<Map.Entry<String, List<Double>>, SimpleFeature> toFeature(SimpleFeatureType CITY, GeometryFactory geometryFactory) {
    return location -> {
        Point point = geometryFactory.createPoint(
          new Coordinate(location.getValue()
            .get(0), location.getValue().get(1)));

        SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(CITY);
        featureBuilder.add(point);
        featureBuilder.add(location.getKey());
        return featureBuilder.buildFeature(null);
    };
}
 
Example 7
Source File: UserMapper.java    From C4SG-Obsolete with MIT License 5 votes vote down vote up
/**
 * Map user data transfer object into user entity
 * 
 * @param userDTO User Data Transfer object
 * @return User
 */	
public User getUserEntityFromDto(UserDTO userDTO){
	User user = map(userDTO, User.class);
	
	if (userDTO.getLatitude() != null && userDTO.getLongitude() != null){
		GeometryFactory gf = new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING));
		Coordinate coordinate = new Coordinate(Double.parseDouble(userDTO.getLongitude()),
				Double.parseDouble(userDTO.getLatitude()));
		com.vividsolutions.jts.geom.Point point = gf.createPoint(coordinate);	
		user.setLocation(point);			
	}
	user.setDisplayFlag(Boolean.valueOf(userDTO.getDisplayFlag()));
	return user;
}
 
Example 8
Source File: SOSSelectionChangedHandler.java    From SensorWebClient with GNU General Public License v2.0 5 votes vote down vote up
private BoundingBox createBoundingBox(Record record) {
    Double llEasting = Double.parseDouble(getValueFor(record, "llEasting"));
    Double llNorthing = Double.parseDouble(getValueFor(record, "llNorthing"));
    Double urEasting = Double.parseDouble(getValueFor(record, "urEasting"));
    Double urNorthing = Double.parseDouble(getValueFor(record, "urNorthing"));

    GeometryFactory factory = new GeometryFactory(new PrecisionModel(), 4326);
    Point ll = factory.createPoint(new Coordinate(llEasting, llNorthing));
    Point ur = factory.createPoint(new Coordinate(urEasting, urNorthing));
    return new BoundingBox(ll, ur, "EPSG:4326");
}
 
Example 9
Source File: WKTWriterTest.java    From jts with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void testWriteLargeNumbers1() {
  PrecisionModel precisionModel = new PrecisionModel(1E9);
  GeometryFactory geometryFactory = new GeometryFactory(precisionModel, 0);
  Point point1 = geometryFactory.createPoint(new Coordinate(123456789012345678d, 10E9));
  assertEquals("POINT (123456789012345680 10000000000)", point1.toText());
}
 
Example 10
Source File: VectorLayerServiceVisibleAreaTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 4 votes vote down vote up
@Test
@DirtiesContext
public void testSaveOrUpdateCreateArea() throws Exception {
	Filter filter;
	List<InternalFeature> oldFeatures;
	List<InternalFeature> newFeatures;
	InternalFeature feature;
	CoordinateReferenceSystem crs = beanLayer.getCrs();
	GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel());
	Geometry geometry;

	login("marino");
	// verify failing
	oldFeatures = new ArrayList<InternalFeature>();
	newFeatures = new ArrayList<InternalFeature>();
	feature = converterService.toInternal(new Feature());
	feature.setId("4");
	feature.setLayer(beanLayer);
	// feature needs a geometry or exceptions all over
	geometry = geometryFactory.createPoint(new Coordinate(5.5, 5.5));
	feature.setGeometry(geometry);
	newFeatures.add(feature);
	try {
		layerService.saveOrUpdate(LAYER_ID, crs, oldFeatures, newFeatures);
		Assert.fail("create area not checked");
	} catch (GeomajasSecurityException gse) {
		Assert.assertEquals(ExceptionCode.FEATURE_CREATE_PROHIBITED, gse.getExceptionCode());
	}
	filter = filterService.createFidFilter(new String[]{"4"});
	oldFeatures = layerService.getFeatures(LAYER_ID,
			crs, filter, null, VectorLayerService.FEATURE_INCLUDE_ATTRIBUTES);
	Assert.assertEquals(0, oldFeatures.size());
	// verify success
	oldFeatures = new ArrayList<InternalFeature>();
	newFeatures = new ArrayList<InternalFeature>();
	feature = converterService.toInternal(new Feature());
	feature.setId("4");
	feature.setLayer(beanLayer);
	// feature needs a geometry or exceptions all over
	geometry = geometryFactory.createPoint(new Coordinate(1.5, 1.5));
	feature.setGeometry(geometry);
	newFeatures.add(feature);
	layerService.saveOrUpdate(LAYER_ID, crs, oldFeatures, newFeatures);
	filter = filterService.createFidFilter(new String[]{"4"});
	oldFeatures = layerService.getFeatures(LAYER_ID,
			crs, filter, null, VectorLayerService.FEATURE_INCLUDE_ATTRIBUTES);
	Assert.assertEquals(1, oldFeatures.size());
}
 
Example 11
Source File: VectorLayerServiceFeatureTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 4 votes vote down vote up
@Test
@DirtiesContext
public void testSaveOrUpdateCreateFeature() throws Exception {
	Filter filter;
	List<InternalFeature> oldFeatures;
	List<InternalFeature> newFeatures;
	InternalFeature feature;
	CoordinateReferenceSystem crs = beanLayer.getCrs();
	GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel());
	Geometry geometry;

	login("marino");
	oldFeatures = new ArrayList<InternalFeature>();
	newFeatures = new ArrayList<InternalFeature>();
	feature = converterService.toInternal(new Feature());
	feature.setId("4");
	feature.setLayer(beanLayer);
	// feature needs a geometry or exceptions all over
	geometry = geometryFactory.createPoint(new Coordinate(1.5, 1.5));
	feature.setGeometry(geometry);		
	newFeatures.add(feature);
	try {
		layerService.saveOrUpdate(LAYER_ID, crs, oldFeatures, newFeatures);
		Assert.fail("create should have failed");
	} catch (GeomajasSecurityException gse) {
		Assert.assertEquals(ExceptionCode.FEATURE_CREATE_PROHIBITED, gse.getExceptionCode());
	}
	filter = filterService.createFidFilter(new String[]{"4"});
	oldFeatures = layerService.getFeatures(LAYER_ID,
			crs, filter, null, VectorLayerService.FEATURE_INCLUDE_ATTRIBUTES);
	Assert.assertEquals(0, oldFeatures.size());

	login("luc");
	oldFeatures = new ArrayList<InternalFeature>();
	newFeatures = new ArrayList<InternalFeature>();
	feature = converterService.toInternal(new Feature());
	feature.setId("4");
	feature.setLayer(beanLayer);
	// feature needs a geometry or exceptions all over
	geometry = geometryFactory.createPoint(new Coordinate(1.5, 1.5));
	feature.setGeometry(geometry);
	newFeatures.add(feature);
	layerService.saveOrUpdate(LAYER_ID, crs, oldFeatures, newFeatures);
	filter = filterService.createFidFilter(new String[]{"4"});
	oldFeatures = layerService.getFeatures(LAYER_ID,
			crs, filter, null, VectorLayerService.FEATURE_INCLUDE_ATTRIBUTES);
	Assert.assertEquals(1, oldFeatures.size());
}
 
Example 12
Source File: PointImpl.java    From mrgeo with Apache License 2.0 4 votes vote down vote up
@Override
public Point toJTS()
{
  GeometryFactory factory = new GeometryFactory();
  return factory.createPoint(new Coordinate(x, y));
}
 
Example 13
Source File: WKTWriterTest.java    From jts with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void testWrite3D() {
  GeometryFactory geometryFactory = new GeometryFactory();
  Point point = geometryFactory.createPoint(new Coordinate(1, 1, 1));
  String wkt = writer3D.write(point);
  assertEquals("POINT (1 1 1)", wkt);
}
 
Example 14
Source File: WKTWriterTest.java    From jts with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void testWriteLargeNumbers3() {
  PrecisionModel precisionModel = new PrecisionModel(1E9);
  GeometryFactory geometryFactory = new GeometryFactory(precisionModel, 0);
  Point point1 = geometryFactory.createPoint(new Coordinate(123456789012345678000000E9d, 10E9));
  assertEquals("POINT (123456789012345690000000000000000 10000000000)", point1.toText());
}
 
Example 15
Source File: WKTWriterTest.java    From jts with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void testWriteLargeNumbers2() {
  PrecisionModel precisionModel = new PrecisionModel(1E9);
  GeometryFactory geometryFactory = new GeometryFactory(precisionModel, 0);
  Point point1 = geometryFactory.createPoint(new Coordinate(1234d, 10E9));
  assertEquals("POINT (1234 10000000000)", point1.toText());
}
 
Example 16
Source File: GeometryTreeModel.java    From jts with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Geometry getGeometry()
{
  GeometryFactory geomFact = new GeometryFactory();
  return geomFact.createPoint(coord);
}
 
Example 17
Source File: GeoJsonReader.java    From jts with GNU Lesser General Public License v2.1 4 votes vote down vote up
private Geometry createPoint(Map<String, Object> geometryMap,
    GeometryFactory geometryFactory) throws ParseException {

  Geometry result = null;

  try {

    @SuppressWarnings("unchecked")
    List<Number> coordinateList = (List<Number>) geometryMap
        .get(GeoJsonConstants.NAME_COORDINATES);

    CoordinateSequence coordinate = this.createCoordinate(coordinateList);

    result = geometryFactory.createPoint(coordinate);

  } catch (RuntimeException e) {
    throw new ParseException("Could not parse Point from GeoJson string.", e);
  }

  return result;
}
 
Example 18
Source File: GPSPoint.java    From traffic-engine with GNU General Public License v3.0 4 votes vote down vote up
public Point getPoint() {
	GeometryFactory gf = new GeometryFactory();
	return gf.createPoint(new Coordinate(lon, lat));
}
 
Example 19
Source File: LAQNImporter.java    From TomboloDigitalConnector with MIT License 4 votes vote down vote up
private Geometry shape(String latitude, String longitude) {
    GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel(), Subject.SRID);
    return geometryFactory
            .createPoint(new Coordinate(Double.parseDouble(longitude), Double.parseDouble(latitude)));
}
 
Example 20
Source File: TestFactory.java    From TomboloDigitalConnector with MIT License 3 votes vote down vote up
/**
 * makeFakeGeometry
 * Returns a point at the offset provided
 * @param xOffset
 * @param yOffset
 * @return A point geometry at xOffset, yOffset
 */
public static Geometry makePointGeometry(Double xOffset, Double yOffset) {
    GeometryFactory geometryFactory = new GeometryFactory();
    Geometry point =  geometryFactory.createPoint(new Coordinate(xOffset, yOffset));
    point.setSRID(Subject.SRID);
    return point;
}