天天看点

使用geotools和jts进行GIS数据生成

使用geotools和jts进行GIS数据生成
           
1,添加maven依赖,如下
           
<!-- https://mvnrepository.com/artifact/org.geotools/gt-geojson -->
		<dependency>
		    <groupId>org.geotools</groupId>
		    <artifactId>gt-geojson</artifactId>
		    <version>17.2</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/org.geotools/gt-data -->
		<dependency>
		    <groupId>org.geotools</groupId>
		    <artifactId>gt-data</artifactId>
		    <version>17.2</version>
		</dependency>
				
		<!-- https://mvnrepository.com/artifact/com.vividsolutions/jts -->
		<dependency>
		    <groupId>com.vividsolutions</groupId>
		    <artifactId>jts</artifactId>
		    <version>1.13</version>
		</dependency>
           

2,You can create new features and add them to this FeatureCollection as needed:

SimpleFeatureType TYPE = DataUtilities.createType("location","geom:Point,name:String");

DefaultFeatureCollection featureCollection = new DefaultFeatureCollection("internal",TYPE);
WKTReader2 wkt = new WKTReader2();

featureCollection.add( SimpleFeatureBuilder.build( TYPE, new Object[]{ wkt.read("POINT(1,2)"), "name1"}, null) );
featureCollection.add( SimpleFeatureBuilder.build( TYPE, new Object[]{ wkt.read("POINT(4,4)"), "name2"}, null) );      
GIS