如何判断GeoTools 的Geometry类型

代码如下,截取自GeoTools文档

public enum Geometries
extends Enum
Constants to identify JTS geometry types, reducing the need for boiler-plate code such as this...
 if (Polygon.class.isAssignableFrom(myObject.getClass()) ||
         MultiPolygon.class.isAssignableFrom(myObject.getClass())) {
     // do polygon thing
     ...
 } else if (LineString.class.isAssignableFrom(myObject.getClass()) ||
         MultiLineString.class.isAssignableFrom(myObject.getClass())) {
     // do line thing
     ....
 } else {
     // do point thing
     ....
 }
 Instead you can do this...
 Geometries geomType = Geometries.get(myObject);
 switch (geomType) {
     case POLYGON:
     case MULTIPOLYGON:
         // do polygon thing
         break;
     case LINESTRING:
     case MULTILINESTRING:
         // do line thing
         break;
     case POINT:
     case MULTIPOINT:
         // do point thing
         break;
     default:
         // e.g. unspecified Geometry, GeometryCollection
         break;
 }
 You can also work with Class objects...
 Class aClas = ...
 Geometries type = Geometries.getForBinding( aClass );
 

你可能感兴趣的:(GIS)