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


Java OGCGeometry.fromGeoJson方法代码示例

本文整理汇总了Java中com.esri.core.geometry.ogc.OGCGeometry.fromGeoJson方法的典型用法代码示例。如果您正苦于以下问题:Java OGCGeometry.fromGeoJson方法的具体用法?Java OGCGeometry.fromGeoJson怎么用?Java OGCGeometry.fromGeoJson使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.esri.core.geometry.ogc.OGCGeometry的用法示例。


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

示例1: evaluate

import com.esri.core.geometry.ogc.OGCGeometry; //导入方法依赖的package包/类
@Override
public Object evaluate(DeferredObject[] arguments) throws HiveException {
	DeferredObject jsonDeferredObject = arguments[0];

	String json = null;

	if (jsonOI.getCategory() == Category.STRUCT){
		//StructObjectInspector structOI = (StructObjectInspector)jsonOI;

		// TODO support structs
	} else {
		PrimitiveObjectInspector primOI = (PrimitiveObjectInspector)jsonOI;
		json = (String)primOI.getPrimitiveJavaObject(jsonDeferredObject.get());
	}

	try {
		OGCGeometry ogcGeom = OGCGeometry.fromGeoJson(json);
	    return GeometryUtils.geometryToEsriShapeBytesWritable(ogcGeom);
	} catch (Exception e) {
		LogUtils.Log_InvalidText(LOG, json);
	}

	return null;
}
 
开发者ID:Esri,项目名称:spatial-framework-for-hadoop,代码行数:25,代码来源:ST_GeomFromGeoJson.java

示例2: testPolygon

import com.esri.core.geometry.ogc.OGCGeometry; //导入方法依赖的package包/类
@Test
public void testPolygon() throws Exception {
	OGCGeometry g = OGCGeometry
			.fromText("POLYGON((-10 -10, 10 -10, 10 10, -10 10, -10 -10), (-5 -5, -5 5, 5 5, 5 -5, -5 -5))");
	assertTrue(g.geometryType().equals("Polygon"));
	OGCPolygon p = (OGCPolygon) g;
	assertTrue(p.numInteriorRing() == 1);
	OGCLineString ls = p.exteriorRing();
	// assertTrue(ls.pointN(1).equals(OGCGeometry.fromText("POINT(10 -10)")));
	boolean b = ls
			.Equals(OGCGeometry
					.fromText("LINESTRING(-10 -10, 10 -10, 10 10, -10 10, -10 -10)"));
	assertTrue(b);
	OGCLineString lsi = p.interiorRingN(0);
	b = lsi.Equals(OGCGeometry
			.fromText("LINESTRING(-5 -5, -5 5, 5 5, 5 -5, -5 -5)"));
	assertTrue(b);
	b = lsi.equals((Object)OGCGeometry
			.fromText("LINESTRING(-5 -5, -5 5, 5 5, 5 -5, -5 -5)"));
	assertTrue(!lsi.Equals(ls));
	OGCMultiCurve boundary = p.boundary();
	String s = boundary.asText();
	assertTrue(s.equals("MULTILINESTRING ((-10 -10, 10 -10, 10 10, -10 10, -10 -10), (-5 -5, -5 5, 5 5, 5 -5, -5 -5))"));

	{
		OGCGeometry g2 = OGCGeometry.fromGeoJson(
				"{\"type\": \"Polygon\", \"coordinates\": [[[1.00000001,1.00000001], [4.00000001,1.00000001], [4.00000001,4.00000001], [1.00000001,4.00000001]]]}");
		OGCGeometry
				.fromGeoJson(
						"{\"type\": \"LineString\", \"coordinates\": [[1.00000001,1.00000001], [7.00000001,8.00000001]]}")
				.intersects(g2);
		OGCGeometry
				.fromGeoJson(
						"{\"type\": \"LineString\", \"coordinates\": [[2.449,4.865], [7.00000001,8.00000001]]}")
				.intersects(g2);

		OGCGeometry g3 = OGCGeometry.fromGeoJson(
				"{\"type\": \"Polygon\", \"coordinates\": [[[1.00000001,1.00000001], [4.00000001,1.00000001], [4.00000001,4.00000001], [1.00000001,4.00000001]]]}");
		boolean bb = g2.equals((Object) g3);
		assertTrue(bb);
	}
}
 
开发者ID:Esri,项目名称:geometry-api-java,代码行数:43,代码来源:TestOGC.java

示例3: testGeometryCollection

import com.esri.core.geometry.ogc.OGCGeometry; //导入方法依赖的package包/类
@Test
public void testGeometryCollection() throws Exception {
	OGCGeometry g = OGCGeometry
			.fromText("GEOMETRYCOLLECTION(POLYGON EMPTY, POINT(1 1), LINESTRING EMPTY, MULTIPOLYGON EMPTY, MULTILINESTRING EMPTY)");
	assertTrue(g.geometryType().equals("GeometryCollection"));
	OGCConcreteGeometryCollection gc = (OGCConcreteGeometryCollection) g;
	assertTrue(gc.numGeometries() == 5);
	assertTrue(gc.geometryN(0).geometryType().equals("Polygon"));
	assertTrue(gc.geometryN(1).geometryType().equals("Point"));
	assertTrue(gc.geometryN(2).geometryType().equals("LineString"));
	assertTrue(gc.geometryN(3).geometryType().equals("MultiPolygon"));
	assertTrue(gc.geometryN(4).geometryType().equals("MultiLineString"));

	g = OGCGeometry
			.fromText("GEOMETRYCOLLECTION(POLYGON EMPTY, POINT(1 1), GEOMETRYCOLLECTION EMPTY, LINESTRING EMPTY, GEOMETRYCOLLECTION(POLYGON EMPTY, POINT(1 1), LINESTRING EMPTY, MULTIPOLYGON EMPTY, MULTILINESTRING EMPTY, MULTIPOINT EMPTY), MULTIPOLYGON EMPTY, MULTILINESTRING EMPTY)");
	assertTrue(g.geometryType().equals("GeometryCollection"));
	gc = (OGCConcreteGeometryCollection) g;
	assertTrue(gc.numGeometries() == 7);
	assertTrue(gc.geometryN(0).geometryType().equals("Polygon"));
	assertTrue(gc.geometryN(1).geometryType().equals("Point"));
	assertTrue(gc.geometryN(2).geometryType().equals("GeometryCollection"));
	assertTrue(gc.geometryN(3).geometryType().equals("LineString"));
	assertTrue(gc.geometryN(4).geometryType().equals("GeometryCollection"));
	assertTrue(gc.geometryN(5).geometryType().equals("MultiPolygon"));
	assertTrue(gc.geometryN(6).geometryType().equals("MultiLineString"));

	OGCConcreteGeometryCollection gc2 = (OGCConcreteGeometryCollection) gc
			.geometryN(4);
	assertTrue(gc2.numGeometries() == 6);
	assertTrue(gc2.geometryN(0).geometryType().equals("Polygon"));
	assertTrue(gc2.geometryN(1).geometryType().equals("Point"));
	assertTrue(gc2.geometryN(2).geometryType().equals("LineString"));
	assertTrue(gc2.geometryN(3).geometryType().equals("MultiPolygon"));
	assertTrue(gc2.geometryN(4).geometryType().equals("MultiLineString"));
	assertTrue(gc2.geometryN(5).geometryType().equals("MultiPoint"));

	ByteBuffer wkbBuffer = g.asBinary();
	g = OGCGeometry.fromBinary(wkbBuffer);

	assertTrue(g.geometryType().equals("GeometryCollection"));
	gc = (OGCConcreteGeometryCollection) g;
	assertTrue(gc.numGeometries() == 7);
	assertTrue(gc.geometryN(0).geometryType().equals("Polygon"));
	assertTrue(gc.geometryN(1).geometryType().equals("Point"));
	assertTrue(gc.geometryN(2).geometryType().equals("GeometryCollection"));
	assertTrue(gc.geometryN(3).geometryType().equals("LineString"));
	assertTrue(gc.geometryN(4).geometryType().equals("GeometryCollection"));
	assertTrue(gc.geometryN(5).geometryType().equals("MultiPolygon"));
	assertTrue(gc.geometryN(6).geometryType().equals("MultiLineString"));

	gc2 = (OGCConcreteGeometryCollection) gc.geometryN(4);
	assertTrue(gc2.numGeometries() == 6);
	assertTrue(gc2.geometryN(0).geometryType().equals("Polygon"));
	assertTrue(gc2.geometryN(1).geometryType().equals("Point"));
	assertTrue(gc2.geometryN(2).geometryType().equals("LineString"));
	assertTrue(gc2.geometryN(3).geometryType().equals("MultiPolygon"));
	assertTrue(gc2.geometryN(4).geometryType().equals("MultiLineString"));
	assertTrue(gc2.geometryN(5).geometryType().equals("MultiPoint"));

	String wktString = g.asText();
	assertTrue(wktString
			.equals("GEOMETRYCOLLECTION (POLYGON EMPTY, POINT (1 1), GEOMETRYCOLLECTION EMPTY, LINESTRING EMPTY, GEOMETRYCOLLECTION (POLYGON EMPTY, POINT (1 1), LINESTRING EMPTY, MULTIPOLYGON EMPTY, MULTILINESTRING EMPTY, MULTIPOINT EMPTY), MULTIPOLYGON EMPTY, MULTILINESTRING EMPTY)"));

	g = OGCGeometry
			.fromGeoJson("{\"type\" : \"GeometryCollection\", \"geometries\" : [{\"type\" : \"Polygon\", \"coordinates\" : []}, {\"type\" : \"Point\", \"coordinates\" : [1, 1]}, {\"type\" : \"GeometryCollection\", \"geometries\" : []}, {\"type\" : \"LineString\", \"coordinates\" : []}, {\"type\" : \"GeometryCollection\", \"geometries\" : [{\"type\": \"Polygon\", \"coordinates\" : []}, {\"type\" : \"Point\", \"coordinates\" : [1,1]}, {\"type\" : \"LineString\", \"coordinates\" : []}, {\"type\" : \"MultiPolygon\", \"coordinates\" : []}, {\"type\" : \"MultiLineString\", \"coordinates\" : []}, {\"type\" : \"MultiPoint\", \"coordinates\" : []}]}, {\"type\" : \"MultiPolygon\", \"coordinates\" : []}, {\"type\" : \"MultiLineString\", \"coordinates\" : []} ] }");

	wktString = g.asText();
	assertTrue(wktString
			.equals("GEOMETRYCOLLECTION (POLYGON EMPTY, POINT (1 1), GEOMETRYCOLLECTION EMPTY, LINESTRING EMPTY, GEOMETRYCOLLECTION (POLYGON EMPTY, POINT (1 1), LINESTRING EMPTY, MULTIPOLYGON EMPTY, MULTILINESTRING EMPTY, MULTIPOINT EMPTY), MULTIPOLYGON EMPTY, MULTILINESTRING EMPTY)"));
	
	assertTrue(g.equals((Object)OGCGeometry.fromText(wktString)));
	
	assertTrue(g.hashCode() == OGCGeometry.fromText(wktString).hashCode());

}
 
开发者ID:Esri,项目名称:geometry-api-java,代码行数:76,代码来源:TestOGC.java


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