Java Code Examples for com.vividsolutions.jts.geom.PrecisionModel#FLOATING

The following examples show how to use com.vividsolutions.jts.geom.PrecisionModel#FLOATING . 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: 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 2
Source File: AllowAllAuthorization.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
protected Geometry getAuthorizedArea(String layerId) {
	if (null == biggestGeometry) {
		// build Geometry which covers biggest possible area
		Envelope maxBounds = new Envelope(-Float.MAX_VALUE, Float.MAX_VALUE, -Float.MAX_VALUE, Float.MAX_VALUE);
		PrecisionModel precisionModel = new PrecisionModel(PrecisionModel.FLOATING);
		GeometryFactory geometryFactory = new GeometryFactory(precisionModel, 0);
		biggestGeometry = geometryFactory.toGeometry(maxBounds);
	}
	return biggestGeometry;
}
 
Example 3
Source File: DefaultSecurityContext.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
private Geometry areaCombine(String layerId, AreaCombineGetter areaGetter) {
	if (null == authentications || authentications.size() == 0) {
		// no authorizations, so nothing should be allowed
		return null;
	}

	Layer<?> layer = configurationService.getLayer(layerId);
	if (null == layer) {
		log.error("areaCombine on unknown layer " + layerId);
		return null;
	}
	LayerInfo layerInfo = layer.getLayerInfo();

	// base is the max bounds of the layer
	Envelope maxBounds = converterService.toInternal(layerInfo.getMaxExtent());
	PrecisionModel precisionModel = new PrecisionModel(PrecisionModel.FLOATING);
	int srid = geoService.getSridFromCrs(layer.getLayerInfo().getCrs());
	GeometryFactory geometryFactory = new GeometryFactory(precisionModel, srid);
	Geometry geometry = geometryFactory.toGeometry(maxBounds);

	// limit based on authorizations
	for (Authentication authentication : authentications) {
		for (BaseAuthorization authorization : authentication.getAuthorizations()) {
			if (authorization instanceof AreaAuthorization) {
				geometry = geometry.intersection(areaGetter.get((AreaAuthorization) authorization));
			}
		}
	}
	geometry.setSRID(srid); // force srid, even when not set correctly by security service
	return geometry;
}
 
Example 4
Source File: SecurityContextAreaAuthorizationTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void testDefaultVisibleArea() throws Exception {
	DefaultSecurityContext securityContext = (DefaultSecurityContext)this.securityContext;
	List<Authentication> authentications = new ArrayList<Authentication>();
	Authentication auth1 = getBaseAuthentication();
	authentications.add(auth1);
	securityContext.setAuthentications("token", authentications);
	Assert.assertTrue(securityContext.isLayerVisible(LAYER_ID));
	Geometry geometry = securityContext.getVisibleArea(LAYER_ID);
	Assert.assertNotNull(geometry);
	PrecisionModel precisionModel  = new PrecisionModel(PrecisionModel.FLOATING);
	GeometryFactory geometryFactory = new GeometryFactory(precisionModel, LAYER_SRID);
	Coordinate coordinate = new Coordinate();

	coordinate.x = coordinate.y = -86;
	Assert.assertFalse(geometry.contains(geometryFactory.createPoint(coordinate)));
	coordinate.x = -85.05;
	coordinate.y = -85.05;
	Assert.assertTrue(geometry.contains(geometryFactory.createPoint(coordinate)));
	coordinate.x = -85.05;
	coordinate.y = 85.05;
	Assert.assertTrue(geometry.contains(geometryFactory.createPoint(coordinate)));
	coordinate.x = 85.05;
	coordinate.y = -85.05;
	Assert.assertTrue(geometry.contains(geometryFactory.createPoint(coordinate)));
	coordinate.x = 85.05;
	coordinate.y = 85.05;
	Assert.assertTrue(geometry.contains(geometryFactory.createPoint(coordinate)));
	coordinate.x = coordinate.y = 86;
	Assert.assertFalse(geometry.contains(geometryFactory.createPoint(coordinate)));

	Assert.assertFalse(securityContext.isPartlyVisibleSufficient(LAYER_ID));
}
 
Example 5
Source File: SecurityContextAreaAuthorizationTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void testDefaultVisibleAreaOne() throws Exception {
	DefaultSecurityContext securityContext = (DefaultSecurityContext)this.securityContext;
	List<Authentication> authentications = new ArrayList<Authentication>();
	Authentication auth1 = getAuthentication();
	Authentication auth2 = getAreaAuthentication(1);
	authentications.add(auth1);
	authentications.add(auth2);
	securityContext.setAuthentications("token", authentications);

	Geometry geometry = securityContext.getVisibleArea(LAYER_ID);
	Assert.assertNotNull(geometry);
	PrecisionModel precisionModel  = new PrecisionModel(PrecisionModel.FLOATING);
	GeometryFactory geometryFactory = new GeometryFactory(precisionModel, LAYER_SRID);
	Coordinate coordinate = new Coordinate();
	coordinate.x = coordinate.y = 0.5;
	Assert.assertFalse(geometry.contains(geometryFactory.createPoint(coordinate)));
	coordinate.x = coordinate.y = 1.5;
	Assert.assertTrue(geometry.contains(geometryFactory.createPoint(coordinate)));
	coordinate.x = coordinate.y = 2.5;
	Assert.assertTrue(geometry.contains(geometryFactory.createPoint(coordinate)));
	coordinate.x = coordinate.y = 3.5;
	Assert.assertFalse(geometry.contains(geometryFactory.createPoint(coordinate)));
	coordinate.x = coordinate.y = 4.5;
	Assert.assertFalse(geometry.contains(geometryFactory.createPoint(coordinate)));

	Assert.assertFalse(securityContext.isPartlyVisibleSufficient(LAYER_ID));
}
 
Example 6
Source File: SecurityContextAreaAuthorizationTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void testDefaultVisibleAreaTwo() throws Exception {
	DefaultSecurityContext securityContext = (DefaultSecurityContext)this.securityContext;
	List<Authentication> authentications = new ArrayList<Authentication>();
	Authentication auth1 = getAreaAuthentication(1);
	Authentication auth2 = getAreaAuthentication(2);
	authentications.add(auth1);
	authentications.add(auth2);
	securityContext.setAuthentications("token", authentications);

	Geometry geometry = securityContext.getVisibleArea(LAYER_ID);
	Assert.assertNotNull(geometry);
	PrecisionModel precisionModel  = new PrecisionModel(PrecisionModel.FLOATING);
	GeometryFactory geometryFactory = new GeometryFactory(precisionModel, LAYER_SRID);
	Coordinate coordinate = new Coordinate();
	coordinate.x = coordinate.y = 0.5;
	Assert.assertFalse(geometry.contains(geometryFactory.createPoint(coordinate)));
	coordinate.x = coordinate.y = 1.5;
	Assert.assertFalse(geometry.contains(geometryFactory.createPoint(coordinate)));
	coordinate.x = coordinate.y = 2.5;
	Assert.assertTrue(geometry.contains(geometryFactory.createPoint(coordinate)));
	coordinate.x = coordinate.y = 3.5;
	Assert.assertFalse(geometry.contains(geometryFactory.createPoint(coordinate)));
	coordinate.x = coordinate.y = 4.5;
	Assert.assertFalse(geometry.contains(geometryFactory.createPoint(coordinate)));

	Assert.assertFalse(securityContext.isPartlyVisibleSufficient(LAYER_ID));
}
 
Example 7
Source File: OddFeatureAuthorization.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
protected Geometry getAuthorizedArea(String layerId) {
	if (null == biggestGeometry) {
		// build Geometry which covers biggest possible area
		Envelope maxBounds = new Envelope(-Double.MAX_VALUE, Double.MAX_VALUE,
				-Double.MAX_VALUE, Double.MAX_VALUE);
		PrecisionModel precisionModel = new PrecisionModel(PrecisionModel.FLOATING);
		GeometryFactory geometryFactory = new GeometryFactory(precisionModel, 0);
		biggestGeometry = geometryFactory.toGeometry(maxBounds);
	}
	return biggestGeometry;
}
 
Example 8
Source File: CustomBeanLayerTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Before
public void setupBeans() throws LayerException {
	GeometryFactory factory = new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING), 4329);
	LinearRing shell = factory.createLinearRing(new Coordinate[] { new Coordinate(0, 0), new Coordinate(1, 0),
			new Coordinate(1, 1), new Coordinate(0, 1), new Coordinate(0, 0), });
	Polygon p = factory.createPolygon(shell, null);
	MultiPolygon expected = factory.createMultiPolygon(new Polygon[] { p });
	CustomBean cb = new CustomBean();
	cb.setId(1);
	cb.setGeometry(expected);
	cb.setName("testbean");
	layer.saveOrUpdate(cb);
}