当前位置: 首页>>代码示例>>Java>>正文


Java WktService类代码示例

本文整理汇总了Java中org.geomajas.geometry.service.WktService的典型用法代码示例。如果您正苦于以下问题:Java WktService类的具体用法?Java WktService怎么用?Java WktService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


WktService类属于org.geomajas.geometry.service包,在下文中一共展示了WktService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getCentroid

import org.geomajas.geometry.service.WktService; //导入依赖的package包/类
@Test
public void getCentroid() throws WktException, ParseException {
	Assert.assertTrue(jts.getCentroid().getCoordinate().x - gwt.getCentroid().getX() < 1);
	Assert.assertTrue(jts.getCentroid().getCoordinate().y - gwt.getCentroid().getY() < 1);

	String wkt = "POLYGON ((948732.820500011 6078756.569848541, 1068024.3649477751 6028202.01937218, "
			+ "1072333.0579502126 5998997.156511122, 1055305.3793291312 5958871.450440632, 1105675.0935204166 "
			+ "5929144.458480931, 1162476.2079476311 5924715.38833866, 1153645.9759600186 5858183.406784581, "
			+ "1104605.1110124618 5830956.472744024, 1066165.5338210524 5840392.513424949, 946203.9886702409 "
			+ "6074778.917027304, 948732.820500011 6078756.569848541))";
	Geometry geometry = GeometryConverter.toGwt(WktService.toGeometry(wkt));
	Coordinate c = geometry.getCentroid();

	WKTReader r = new WKTReader(jtsFactory);
	com.vividsolutions.jts.geom.Geometry geometry2 = r.read(wkt);
	com.vividsolutions.jts.geom.Point c2 = geometry2.getCentroid();

	Assert.assertEquals(c2.getY(), c.getY(), DELTA);
	Assert.assertEquals(c2.getX(), c.getX(), DELTA);
}
 
开发者ID:geomajas,项目名称:geomajas-project-client-gwt,代码行数:21,代码来源:GwtLinearRingTest.java

示例2: testMultiPolygon

import org.geomajas.geometry.service.WktService; //导入依赖的package包/类
@Test
public void testMultiPolygon() throws Exception {
	JSONObject o = JsonTestUtil.parse("{\"geometry\":{\n" + 
			"    \"type\": \"MultiPolygon\", \n" + 
			"    \"coordinates\": [\n" + 
			"        [\n" + 
			"            [[40, 40], [20, 45], [45, 30], [40, 40]]\n" + 
			"        ], \n" + 
			"        [\n" + 
			"            [[20, 35], [10, 30], [10, 10], [30, 5], [45, 20], [20, 35]], \n" + 
			"            [[30, 20], [20, 15], [20, 25], [30, 20]]\n" + 
			"        ]\n" + 
			"    ]\n" + 
			"}\n" + 
			"}");
	Geometry g = JsonService.getGeometryValue(o, "geometry");
	Assert.assertEquals("MULTIPOLYGON (((40.0 40.0, 20.0 45.0, 45.0 30.0, 40.0 40.0)), "
			+ "((20.0 35.0, 10.0 30.0, 10.0 10.0, 30.0 5.0, 45.0 20.0, 20.0 35.0), "
			+ "(30.0 20.0, 20.0 15.0, 20.0 25.0, 30.0 20.0)))",WktService.toWkt(g));
}
 
开发者ID:geomajas,项目名称:geomajas-project-client-gwt2,代码行数:21,代码来源:JsonServiceTest.java

示例3: testCreateEditable

import org.geomajas.geometry.service.WktService; //导入依赖的package包/类
@Test
@DirtiesContext
@SuppressWarnings("unchecked")
public void testCreateEditable() throws Exception {
	String newGeometryWkt = "MULTIPOLYGON (((0 -1, 1 -1, 1 0, 0 0, 0 -1)))";
	Crs crs = geoService.getCrs2(notAllEditableLayer.getLayerInfo().getCrs());
	List<InternalFeature> oldFeatures = new ArrayList<InternalFeature>();
	List<InternalFeature> newFeatures = new ArrayList<InternalFeature>();
	InternalFeature feature = converterService.toInternal(new Feature());
	Map<String, Attribute> attributes = new HashMap<String, Attribute>();
	feature.setAttributes(attributes);
	feature.setId("2");
	feature.setLayer(notAllEditableLayer);
	// feature needs a geometry or exceptions all over
	feature.setGeometry(converterService.toInternal(WktService.toGeometry(newGeometryWkt)));
	attributes.put(COUNTRY_CODE_ATTR, new StringAttribute("newCode"));
	attributes.put(COUNTRY_NAME_ATTR, new StringAttribute("newName"));
	newFeatures.add(feature);
	try {
		layerService.saveOrUpdate(LAYER_NOT_ALL_EDITABLE_ID, crs, oldFeatures, newFeatures);
		Assert.fail("Should throw an exception.");
	} catch (GeomajasException ge) {
		assertThat(ge.getExceptionCode()).isEqualTo(ExceptionCode.CANNOT_CREATE_FEATURE_WITHOUT_GEOMETRY);
	}
}
 
开发者ID:geomajas,项目名称:geomajas-project-server,代码行数:26,代码来源:VectorLayerServiceTest.java

示例4: toWkt

import org.geomajas.geometry.service.WktService; //导入依赖的package包/类
/**
 * Format the given geometry object to Well Known Text representation.
 * 
 * @param geometry
 *            The geometry to format.
 * @return Get WKT representation of the given geometry, or null in case something went wrong.
 */
public String toWkt(Geometry geometry) {
	try {
		return WktService.toWkt(geometry);
	} catch (WktException e) {
		return null;
	}
}
 
开发者ID:geomajas,项目名称:geomajas-project-client-gwt,代码行数:15,代码来源:GeometryServiceImpl.java

示例5: toGeometry

import org.geomajas.geometry.service.WktService; //导入依赖的package包/类
/**
 * Parse the given Well Known Text string into a geometry.
 * 
 * @param wkt
 *            The WKT text.
 * @return The resulting geometry, or null in case something went wrong.
 */
public Geometry toGeometry(String wkt) {
	try {
		return WktService.toGeometry(wkt);
	} catch (WktException e) {
		return null;
	}
}
 
开发者ID:geomajas,项目名称:geomajas-project-client-gwt,代码行数:15,代码来源:GeometryServiceImpl.java

示例6: onMapModelChanged

import org.geomajas.geometry.service.WktService; //导入依赖的package包/类
/**
 * add some world paintables, these will be printed too !!!
 */
@Override
public void onMapModelChanged(MapModelChangedEvent event) {
	try {
		Rectangle bg = new Rectangle("background");
		bg.setBounds(new Bbox(0, 0, 4000000, 4000000));
		bg.setStyle(new ShapeStyle("#FFFFFF", 1f, "#FFFFFF", 1f, 2));
		map.registerWorldPaintable(bg);
		Rectangle rect = new Rectangle("my rect");
		rect.setBounds(new Bbox(0, 0, 1000000, 1000000));
		rect.setStyle(createStyle("#FF0000"));
		map.registerWorldPaintable(rect);
		Circle circle = new Circle("my circle");
		circle.setPosition(new Coordinate(1500000, 1500000));
		circle.setRadius(500000f);
		circle.setStyle(createStyle("#00FF00"));
		map.registerWorldPaintable(circle);
		GfxGeometry triangle = new GfxGeometry("triangle");
		Geometry geom;
		geom = WktService
				.toGeometry("POLYGON ((2000000 2000000, 3000000 2000000,3000000 3000000,2000000 2000000))");
		triangle.setGeometry(GeometryConverter.toGwt(geom));
		triangle.setStyle(createStyle("#FFFF00"));
		map.registerWorldPaintable(triangle);
		Image image = new Image("osgeo");
		image.setHref("http://live.osgeo.org/_images/logo-geomajas.png");
		image.setBounds(new Bbox(0, 2000000, 1000000, 1000000));
		image.setStyle(new PictureStyle(0.7));
		map.registerWorldPaintable(image);
		Text text = new Text("my text", "Hello world", new Coordinate(2000000, 2000000), new FontStyle(
				"#00FFF0", 50, "Verdana", "bold", "italic"));
		map.registerWorldPaintable(text);
	} catch (WktException e) {
	}
}
 
开发者ID:geomajas,项目名称:geomajas-project-client-gwt,代码行数:38,代码来源:PrintingPanel.java

示例7: testCreateFromSingleFeature

import org.geomajas.geometry.service.WktService; //导入依赖的package包/类
@Test
public void testCreateFromSingleFeature() throws Exception {
	JsonFeatureFactory factory = new JsonFeatureFactory();
	FeatureCollection c = factory
			.createCollection(
					JsonTestUtil
							.parse("{ \"type\": \"Feature\",\n" + 
									"        \"geometry\": {\"type\": \"Point\", \"coordinates\": [102.0, 0.5]},\n" + 
									"        \"properties\": {\"prop0\": \"value0\"}\n" + 
									"        }"), null);
	Assert.assertEquals(1, c.getFeatures().size());
	Feature f1 = c.getFeatures().get(0);
	Assert.assertEquals("value0", f1.getAttributeValue("prop0"));
	Assert.assertEquals("POINT (102.0 0.5)", WktService.toWkt(f1.getGeometry()));
}
 
开发者ID:geomajas,项目名称:geomajas-project-client-gwt2,代码行数:16,代码来源:JsonFeatureFactoryTest.java

示例8: testPoint

import org.geomajas.geometry.service.WktService; //导入依赖的package包/类
@Test
public void testPoint() throws Exception {
	JSONObject o = JsonTestUtil.parse("{\"geometry\":{\n" + 
			"    \"type\": \"Point\", \n" + 
			"    \"coordinates\": [30, 10]\n" + 
			"}}");
	Geometry g = JsonService.getGeometryValue(o, "geometry");
	Assert.assertEquals("POINT (30.0 10.0)",WktService.toWkt(g));
}
 
开发者ID:geomajas,项目名称:geomajas-project-client-gwt2,代码行数:10,代码来源:JsonServiceTest.java

示例9: testLineString

import org.geomajas.geometry.service.WktService; //导入依赖的package包/类
@Test
public void testLineString() throws Exception {
	JSONObject o = JsonTestUtil.parse("{\"geometry\":{\n" + 
			"    \"type\": \"LineString\", \n" + 
			"    \"coordinates\": [\n" + 
			"        [30, 10], [10, 30], [40, 40]\n" + 
			"    ]\n" + 
			"}}");
	Geometry g = JsonService.getGeometryValue(o, "geometry");
	Assert.assertEquals("LINESTRING (30.0 10.0, 10.0 30.0, 40.0 40.0)",WktService.toWkt(g));
}
 
开发者ID:geomajas,项目名称:geomajas-project-client-gwt2,代码行数:12,代码来源:JsonServiceTest.java

示例10: testPolygon

import org.geomajas.geometry.service.WktService; //导入依赖的package包/类
@Test
public void testPolygon() throws Exception {
	JSONObject o = JsonTestUtil.parse("{\"geometry\":{\n" + 
			"    \"type\": \"Polygon\", \n" + 
			"    \"coordinates\": [\n" + 
			"        [[35, 10], [45, 45], [15, 40], [10, 20], [35, 10]], \n" + 
			"        [[20, 30], [35, 35], [30, 20], [20, 30]]\n" + 
			"    ]\n" + 
			"}}");
	Geometry g = JsonService.getGeometryValue(o, "geometry");
	Assert.assertEquals("POLYGON ((35.0 10.0, 45.0 45.0, 15.0 40.0, 10.0 20.0, 35.0 10.0),"
			+ " (20.0 30.0, 35.0 35.0, 30.0 20.0, 20.0 30.0))",WktService.toWkt(g));
}
 
开发者ID:geomajas,项目名称:geomajas-project-client-gwt2,代码行数:14,代码来源:JsonServiceTest.java

示例11: testMultiPoint

import org.geomajas.geometry.service.WktService; //导入依赖的package包/类
@Test
public void testMultiPoint() throws Exception {
	JSONObject o = JsonTestUtil.parse("{\"geometry\":{\n" + 
			"    \"type\": \"MultiPoint\", \n" + 
			"    \"coordinates\": [\n" + 
			"        [10, 40], [40, 30], [20, 20], [30, 10]\n" + 
			"    ]\n" + 
			"}}");
	Geometry g = JsonService.getGeometryValue(o, "geometry");
	Assert.assertEquals("MULTIPOINT ((10.0 40.0), (40.0 30.0), (20.0 20.0), (30.0 10.0))",WktService.toWkt(g));
}
 
开发者ID:geomajas,项目名称:geomajas-project-client-gwt2,代码行数:12,代码来源:JsonServiceTest.java

示例12: testMultiLineString

import org.geomajas.geometry.service.WktService; //导入依赖的package包/类
@Test
public void testMultiLineString() throws Exception {
	JSONObject o = JsonTestUtil.parse("{\"geometry\":{\n" + 
			"    \"type\": \"MultiLineString\", \n" + 
			"    \"coordinates\": [\n" + 
			"        [[10, 10], [20, 20], [10, 40]], \n" + 
			"        [[40, 40], [30, 30], [40, 20], [30, 10]]\n" + 
			"    ]\n" + 
			"}}");
	Geometry g = JsonService.getGeometryValue(o, "geometry");
	Assert.assertEquals("MULTILINESTRING ((10.0 10.0, 20.0 20.0, 10.0 40.0), "
			+ "(40.0 40.0, 30.0 30.0, 40.0 20.0, 30.0 10.0))",WktService.toWkt(g));
}
 
开发者ID:geomajas,项目名称:geomajas-project-client-gwt2,代码行数:14,代码来源:JsonServiceTest.java

示例13: onGeometryBtnClicked

import org.geomajas.geometry.service.WktService; //导入依赖的package包/类
@UiHandler("geometryBtn")
public void onGeometryBtnClicked(ClickEvent event) {
	try {
		Geometry polygon = WktService
				.toGeometry("POLYGON ((0 0, 0 0.7, 0.7 0.7, 0 0),(0.1 0.2, 0.1 0.4, 0.3 0.4, 0.1 0.2))");
		Geometry line = WktService.toGeometry("LINESTRING (-2 0, -2 0.7, -1.3 0, -1.3 0.7)");
		Geometry point = WktService.toGeometry("POINT (-3.5 0.5)");
		Geometry multiPolygon = new Geometry(Geometry.MULTI_POLYGON, 0, 5);
		Matrix m1 = new Matrix(1, 0, 0, 1, -0.5, -2);
		Matrix m2 = new Matrix(1, 0, 0, 1, 0.5, -2);
		Matrix m3 = new Matrix(1, 0, 0, 1, 0, -1);
		multiPolygon.setGeometries(new Geometry[] { transform(polygon, m1), transform(polygon, m2),
				transform(polygon, m3), });
		Geometry multiLinestring = new Geometry(Geometry.MULTI_LINE_STRING, 0, 5);
		multiLinestring.setGeometries(new Geometry[] { transform(line, m1), transform(line, m2),
				transform(line, m3), });
		Geometry mp = new Geometry(Geometry.MULTI_POINT, 0, 5);
		mp.setGeometries(new Geometry[] { transform(point, m1), transform(point, m2), transform(point, m3), });
		container.add(scaleAndStyle(polygon));
		container.add(scaleAndStyle(line));
		container.add(scaleAndStyle(point));
		container.add(scaleAndStyle(multiPolygon));
		container.add(scaleAndStyle(multiLinestring));
		container.add(scaleAndStyle(mp));
	} catch (WktException e) {
		// not possible
	}
}
 
开发者ID:geomajas,项目名称:geomajas-project-client-gwt2,代码行数:29,代码来源:WorldSpaceRenderingPanel.java

示例14: testUpdateEditable

import org.geomajas.geometry.service.WktService; //导入依赖的package包/类
@Test
@DirtiesContext
@SuppressWarnings("unchecked")
public void testUpdateEditable() throws Exception {
	String newGeometryWkt = "MULTIPOLYGON (((0 -1,1 -1,1 0,0 0,0 -1)))";
	Filter filter = filterService.createFidFilter(new String[]{"1"});
	Crs crs = geoService.getCrs2(notAllEditableLayer.getLayerInfo().getCrs());
	List<InternalFeature> oldFeatures = layerService.getFeatures(LAYER_NOT_ALL_EDITABLE_ID,
			crs, filter, null, VectorLayerService.FEATURE_INCLUDE_ATTRIBUTES);
	Assert.assertEquals(1, oldFeatures.size());
	InternalFeature feature = oldFeatures.get(0);
	List<InternalFeature> newFeatures = new ArrayList<InternalFeature>();
	feature = feature.clone();
	feature.getAttributes().put(COUNTRY_CODE_ATTR, new StringAttribute("newCode"));
	feature.getAttributes().put(COUNTRY_NAME_ATTR, new StringAttribute("newName"));
	feature.setGeometry(converterService.toInternal(WktService.toGeometry(newGeometryWkt)));
	newFeatures.add(feature);
	layerService.saveOrUpdate(LAYER_NOT_ALL_EDITABLE_ID, crs, oldFeatures, newFeatures);

	Iterator<Country> iterator =
			(Iterator<Country>) notAllEditableLayer.getElements(filterService.createTrueFilter(), 0, 0);
	int count = 0;
	while (iterator.hasNext()) {
		Country country = iterator.next();
		count++;
		if (1 == country.getId()) {
			assertThat(country.getCountry()).isEqualTo("CODE"); // not overwritten
			assertThat(country.getName()).isEqualTo("newName"); // overwritten
			assertThat(country.getGeometry()).isEqualTo(
					"MULTIPOLYGON(((0 0,1 0,1 1,0 1,0 0)))"); // not overwritten
		}
	}
	Assert.assertEquals(1, count);
}
 
开发者ID:geomajas,项目名称:geomajas-project-server,代码行数:35,代码来源:VectorLayerServiceTest.java

示例15: testCreateFromCollection

import org.geomajas.geometry.service.WktService; //导入依赖的package包/类
@Test
public void testCreateFromCollection() throws Exception {
	List<AttributeDescriptor> l = new ArrayList<AttributeDescriptor>();
	l.add(new AttributeDescriptorImpl(new PrimitiveAttributeTypeImpl(PrimitiveType.INTEGER), "osm_id"));
	l.add(new AttributeDescriptorImpl(new PrimitiveAttributeTypeImpl(PrimitiveType.DATE), "lastchange"));
	l.add(new AttributeDescriptorImpl(new PrimitiveAttributeTypeImpl(PrimitiveType.STRING), "type"));
	l.add(new AttributeDescriptorImpl(new PrimitiveAttributeTypeImpl(PrimitiveType.STRING), "name"));
	l.add(new AttributeDescriptorImpl(new PrimitiveAttributeTypeImpl(PrimitiveType.INTEGER), "population"));
	when(layer.getAttributeDescriptors()).thenReturn(l);
	JsonFeatureFactory factory = new JsonFeatureFactory();
	FeatureCollection c = factory
			.createCollection(
					JsonTestUtil
							.parse("{\"type\":\"FeatureCollection\","
									+ "\"features\":[{\"type\":\"Feature\",\"id\":\"place.1\","
									+ "\"geometry\":{\"type\":\"Point\",\"coordinates\":[4.4436244,50.4120332]},"
									+ "\"geometry_name\":\"geom\",\"properties\":"
									+ "{\"osm_id\":9002746,\"lastchange\":\"2008-10-03T10:29:40.046-04:00\","
									+ "\"type\":\"city\",\"name\":\"Charleroi\",\"population\":203000}},"
									+ "{\"type\":\"Feature\",\"id\":\"place.2\",\"geometry\":"
									+ "{\"type\":\"Point\",\"coordinates\":[4.3487134,50.883392]},"
									+ "\"geometry_name\":\"geom\",\"properties\":{\"osm_id\":17428149,"
									+ "\"lastchange\":\"2008-10-03T10:29:40.046-04:00\",\"type\":\"village\",\"name\":\"Laken - Laeken\","
									+ "\"population\":null}}],\"crs\":{\"type\":\"EPSG\","
									+ "\"properties\":{\"code\":\"4326\"}}}"), layer);
	Assert.assertEquals(2, c.getFeatures().size());
	Feature f1 = c.getFeatures().get(0);
	Assert.assertEquals(9002746, f1.getAttributeValue("osm_id"));
	Assert.assertEquals(new Date(1223044180046L), (Date) f1.getAttributeValue("lastchange"));
	Assert.assertEquals("city", f1.getAttributeValue("type"));
	Assert.assertEquals("Charleroi", f1.getAttributeValue("name"));
	Assert.assertEquals(203000, f1.getAttributeValue("population"));
	Assert.assertEquals("POINT (4.4436244 50.4120332)", WktService.toWkt(f1.getGeometry()));
	Feature f2 = c.getFeatures().get(1);
	Assert.assertEquals(17428149, f2.getAttributeValue("osm_id"));
	Assert.assertEquals(new Date(1223044180046L), (Date) f2.getAttributeValue("lastchange"));
	Assert.assertEquals("village", f2.getAttributeValue("type"));
	Assert.assertEquals("Laken - Laeken", f2.getAttributeValue("name"));
	Assert.assertNull(f2.getAttributeValue("population"));
	Assert.assertEquals("POINT (4.3487134 50.883392)", WktService.toWkt(f2.getGeometry()));
}
 
开发者ID:geomajas,项目名称:geomajas-project-client-gwt2,代码行数:42,代码来源:JsonFeatureFactoryTest.java


注:本文中的org.geomajas.geometry.service.WktService类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。