commit 81edf6c78cc6f32925981263e5b68755c8633028 Author: unknown Date: Tue Apr 16 17:26:55 2024 +0800 添加项目 diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..37d929f --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..d714280 --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..82dbec8 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..80bb434 --- /dev/null +++ b/pom.xml @@ -0,0 +1,86 @@ + + 4.0.0 + + org.example + CutFillDemo + 1.0-SNAPSHOT + jar + + CutFillDemo + http://maven.apache.org + + + UTF-8 + 32-SNAPSHOT + + + + nexus-aliyun + nexus-aliyun + https://maven.aliyun.com/repository/public + + true + + + false + + + + osgeo + OSGeo Release Repository + https://repo.osgeo.org/repository/release/ + false + true + + + osgeo-snapshot + OSGeo Snapshot Repository + https://repo.osgeo.org/repository/snapshot/ + true + false + + + + + org.springframework.boot + spring-boot-starter-web + 2.0.4.RELEASE + + + org.geotools + gt-epsg-hsql + ${geotools.version} + + + org.geotools + gt-geotiff + ${geotools.version} + + + org.geotools + gt-image + ${geotools.version} + + + org.geotools + gt-shapefile + ${geotools.version} + + + org.geotools + gt-wms + ${geotools.version} + + + org.geotools + gt-swing + ${geotools.version} + + + org.geotools + gt-grid + ${geotools.version} + + + diff --git a/src/main/java/org/example/CutFillDemo.java b/src/main/java/org/example/CutFillDemo.java new file mode 100644 index 0000000..45a3ca2 --- /dev/null +++ b/src/main/java/org/example/CutFillDemo.java @@ -0,0 +1,17 @@ +package org.example; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * Hello world! + * + */ +@SpringBootApplication +public class CutFillDemo +{ + public static void main( String[] args ) + { + SpringApplication.run(CutFillDemo.class,args); + } +} diff --git a/src/main/java/org/example/test/Caclelate.java b/src/main/java/org/example/test/Caclelate.java new file mode 100644 index 0000000..523a4b0 --- /dev/null +++ b/src/main/java/org/example/test/Caclelate.java @@ -0,0 +1,62 @@ +package org.example.test; + +import org.geotools.api.geometry.Position; +import org.geotools.api.referencing.crs.CoordinateReferenceSystem; +import org.geotools.coverage.grid.GridCoordinates2D; +import org.geotools.coverage.grid.GridCoverage2D; +import org.geotools.coverage.grid.GridEnvelope2D; +import org.geotools.coverage.grid.GridGeometry2D; +import org.geotools.coverage.processing.Operations; +import org.geotools.gce.geotiff.GeoTiffReader; +import org.geotools.geometry.Position2D; +import org.geotools.referencing.CRS; +import org.geotools.util.factory.Hints; + +import java.awt.image.RenderedImage; +import java.io.File; + +public class Caclelate { + public static void main(String[] args) throws Exception { + + long time=System.currentTimeMillis(); + + File file = new File("src\\main\\resources\\public\\data\\ASTGTMV003_N23E113_dem.tif"); + double[] coor = new double[]{113.530987,23.652041}; + /** + * Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER:设置经度为第一轴顺序 + * + */ + GeoTiffReader reader = new GeoTiffReader(file, new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE)); + GridCoverage2D coverage = reader.read(null); + + //设置坐标系 + CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:4326"); + // 将 GridCoverage 进行重采样转换为另一个 CRS + coverage = (GridCoverage2D) Operations.DEFAULT.resample(coverage, targetCRS); + + CoordinateReferenceSystem crs = coverage.getCoordinateReferenceSystem2D(); + +// Envelope env = coverage.getEnvelope(); + RenderedImage image = coverage.getRenderedImage(); + // 设置经纬度及坐标系等信息 + Position position = new Position2D(coor[1], coor[0]); + GridGeometry2D gridGeometry = coverage.getGridGeometry(); + GridCoordinates2D gridPoint = gridGeometry.worldToGrid(position); + double[] elevation = new double[1]; + coverage.evaluate(gridPoint,elevation); + double height = elevation[0]; // 这里的高度就是查询位置的高程值 + System.out.println("---------"+height);//---------108.0 +// +// // assume double +// float[] f1 = (float[]) coverage.evaluate(position); +// double[] doubleArray = new double[f1.length]; +// for (int i = 0; i < f1.length; i++) { +// doubleArray[i] = (double) f1[i]; +// } +// double[] sample = doubleArray; +// +// // resample with the same array +// sample = coverage.evaluate(position, sample); +// System.out.println(sample); + } +} diff --git a/src/main/java/org/example/test/CreateGrid.java b/src/main/java/org/example/test/CreateGrid.java new file mode 100644 index 0000000..eea0182 --- /dev/null +++ b/src/main/java/org/example/test/CreateGrid.java @@ -0,0 +1,185 @@ +package org.example.test; + +import org.example.utils.IntersectionBuilder; +import org.geotools.api.data.FeatureSource; +import org.geotools.api.data.FileDataStore; +import org.geotools.api.data.FileDataStoreFinder; +import org.geotools.api.data.SimpleFeatureSource; +import org.geotools.api.feature.simple.SimpleFeature; +import org.geotools.api.feature.simple.SimpleFeatureType; +import org.geotools.api.referencing.crs.CoordinateReferenceSystem; +import org.geotools.api.style.Style; +import org.geotools.data.DataUtilities; +import org.geotools.data.collection.CollectionFeatureSource; +import org.geotools.data.collection.ListFeatureCollection; +import org.geotools.data.simple.SimpleFeatureCollection; +import org.geotools.data.store.EmptyFeatureCollection; +import org.geotools.feature.DefaultFeatureCollection; +import org.geotools.feature.FeatureCollection; +import org.geotools.feature.simple.SimpleFeatureBuilder; +import org.geotools.feature.simple.SimpleFeatureTypeBuilder; +import org.geotools.filter.FilterFactoryImpl; +import org.geotools.filter.function.color.ConstrastFunction; +import org.geotools.geometry.jts.JTSFactoryFinder; +import org.geotools.geometry.jts.ReferencedEnvelope; +import org.geotools.grid.Grids; +import org.geotools.map.FeatureLayer; +import org.geotools.map.Layer; +import org.geotools.map.MapContent; +import org.geotools.referencing.CRS; +import org.geotools.referencing.crs.DefaultGeographicCRS; +import org.geotools.styling.FillImpl; +import org.geotools.styling.SLD; +import org.geotools.swing.JMapFrame; +import org.geotools.swing.data.JFileDataStoreChooser; +import org.locationtech.jts.geom.*; +import org.locationtech.jts.operation.buffer.BufferOp; +import org.locationtech.jts.operation.buffer.BufferParameters; + +import java.io.File; +import java.util.*; + +public class CreateGrid { + private static SimpleFeatureType createFeatureType() { + + SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); + builder.setName("Location"); + builder.setCRS(DefaultGeographicCRS.WGS84); // <- Coordinate reference system + + // add attributes in order + builder.add("the_geom", Polygon.class); + builder.length(15).add("name", String.class); // <- 15 chars width for name field + builder.add("id", Integer.class); + + // build the type + final SimpleFeatureType LOCATION = builder.buildFeatureType(); + + return LOCATION; + } + public static void main(String[] args) throws Exception{ + + // 假设我们使用WGS84坐标系统 + CoordinateReferenceSystem crs = CRS.decode("EPSG:4326"); + + // 定义矩形的左下角和右上角坐标(WGS84) + List coords = new ArrayList(){{ + add(new double[]{113.52896835361318, 23.654018962759377}); + add(new double[]{113.529270627066524, 23.654027766840539 }); + add(new double[]{ 113.529294104616298, 23.653772448486752}); + add(new double[]{ 113.528977157694356, 23.653763644405586 }); + add(new double[]{113.52896835361318, 23.654018962759377}); + }}; + // 创建矩形的四个角点坐标 + Coordinate[] coordinates = new Coordinate[5]; + coordinates[0] = new Coordinate(coords.get(0)[0], coords.get(0)[1]); + coordinates[1] = new Coordinate(coords.get(1)[0], coords.get(1)[1]); + coordinates[2] = new Coordinate(coords.get(2)[0], coords.get(2)[1]); + coordinates[3] = new Coordinate(coords.get(3)[0], coords.get(3)[1]); + // 闭合多边形,复制第一个坐标作为最后一个坐标 + coordinates[4] = new Coordinate(coords.get(0)[0], coords.get(0)[1]); +// coordinates[0] = new Coordinate(0, 0); +// coordinates[1] = new Coordinate(0, 30); +// coordinates[2] = new Coordinate(30, 30); +// coordinates[3] = new Coordinate(30, 0); +// // 闭合多边形,复制第一个坐标作为最后一个坐标 +// coordinates[4] = new Coordinate(0, 0); + // 创建GeometryFactory + GeometryFactory geometryFactory = new GeometryFactory(); + List> featuresProperties = new ArrayList<>(); + + // 创建多边形(矩形) + Map innerPolygon = new HashMap<>(); + Polygon rectangle = geometryFactory.createPolygon(coordinates); + innerPolygon.put("geom",rectangle); + innerPolygon.put("name","输入的面"); + innerPolygon.put("id",1); + featuresProperties.add(innerPolygon); + + // 缓冲区建立,外扩100m + double meter = 100; + double degree = meter/(2*Math.PI*6371004)*360; + + BufferParameters bufferParameters = new BufferParameters(); + bufferParameters.setEndCapStyle(BufferParameters.CAP_FLAT); + bufferParameters.setJoinStyle(BufferParameters.JOIN_MITRE); + BufferOp bufOp = new BufferOp(rectangle,bufferParameters); + Geometry bg = bufOp.getResultGeometry(degree); + + // 构造外边界 + Coordinate[] pcoords = rectangle.getCoordinates(); + Coordinate[] bgcoords = bg.getCoordinates(); + + Map extPolygon1 = new HashMap<>(); + Coordinate[] cords1 = new Coordinate[] {bgcoords[0],bgcoords[1],pcoords[1],pcoords[0],bgcoords[0]}; + Polygon p1 = geometryFactory.createPolygon(cords1); + extPolygon1.put("geom",p1); + extPolygon1.put("name","第一个面"); + extPolygon1.put("id",2); + featuresProperties.add(extPolygon1); + + Map extPolygon2 = new HashMap<>(); + Coordinate[] cords2 = new Coordinate[] {bgcoords[1],bgcoords[2],pcoords[2],pcoords[1],bgcoords[1]}; + Polygon p2 = geometryFactory.createPolygon(cords2); + extPolygon2.put("geom",p2); + extPolygon2.put("name","第二个面"); + extPolygon2.put("id",3); + featuresProperties.add(extPolygon2); +// + Map extPolygon3 = new HashMap<>(); + Coordinate[] cords3 = new Coordinate[] {bgcoords[2],bgcoords[3],pcoords[3],pcoords[2],bgcoords[2]}; + Polygon p3 = geometryFactory.createPolygon(cords3); + extPolygon3.put("geom",p3); + extPolygon3.put("name","第3个面"); + extPolygon3.put("id",4); + featuresProperties.add(extPolygon3); + + Map extPolygon4 = new HashMap<>(); + Coordinate[] cords4 = new Coordinate[] {bgcoords[3],bgcoords[0],pcoords[0],pcoords[3],bgcoords[3]}; + Polygon p4 = geometryFactory.createPolygon(cords4); + extPolygon4.put("geom",p4); + extPolygon4.put("name","第4个面"); + extPolygon4.put("id",5); + featuresProperties.add(extPolygon4); + + final SimpleFeatureType TYPE =createFeatureType(); + DefaultFeatureCollection featureCollection = new DefaultFeatureCollection(); + SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(TYPE); + + featuresProperties.forEach(props->{ + featureBuilder.add(props.get("geom")); + featureBuilder.add(props.get("name")); + featureBuilder.add(props.get("id")); + SimpleFeature feature = featureBuilder.buildFeature((String.valueOf(props.get("id")))); + featureCollection.add(feature); + }); + + +// ReferencedEnvelope bounds = featureCollection.getBounds(); + // 创建grids,0.2度为间隔 + double side = 1/(2*Math.PI*6371004)*360; + ListFeatureCollection collection = new ListFeatureCollection(TYPE); + Iterator iterator = featureCollection.stream().iterator(); + iterator.next(); + collection.add(iterator.next()); + SimpleFeatureSource source = new CollectionFeatureSource(collection); + IntersectionBuilder intersectionBuilder = new IntersectionBuilder(TYPE, source); + SimpleFeatureSource grid = Grids.createSquareGrid(collection.getBounds(), side, -1); + + // Create a map content and add our shapefile to it + MapContent map = new MapContent(); + map.setTitle("填挖方计算-创建网格"); + // 添加初始范围和扩展面图层 + Style style = SLD.createSimpleStyle(featureCollection.getSchema()); + Layer layer = new FeatureLayer(featureCollection, style); + map.addLayer(layer); + + // 添加网格图层 + Style styleBox = SLD.createSimpleStyle(grid.getSchema()); + Layer layerBox = new FeatureLayer(grid, styleBox); + map.addLayer(layerBox); + + // Now display the map + JMapFrame.showMap(map); + + } +} diff --git a/src/main/java/org/example/tutorial/Lession01.java b/src/main/java/org/example/tutorial/Lession01.java new file mode 100644 index 0000000..2857e5c --- /dev/null +++ b/src/main/java/org/example/tutorial/Lession01.java @@ -0,0 +1,53 @@ +package org.example.tutorial; + +import org.geotools.api.data.FileDataStore; +import org.geotools.api.data.FileDataStoreFinder; +import org.geotools.api.data.SimpleFeatureSource; +import org.geotools.api.style.Style; +import org.geotools.data.DataUtilities; +import org.geotools.data.collection.SpatialIndexFeatureCollection; +import org.geotools.map.FeatureLayer; +import org.geotools.map.Layer; +import org.geotools.map.MapContent; +import org.geotools.styling.SLD; +import org.geotools.swing.JMapFrame; +import org.geotools.swing.data.JFileDataStoreChooser; + +import java.io.File; +import java.util.logging.Logger; + +public class Lession01 { + private static final Logger LOGGER = org.geotools.util.logging.Logging.getLogger(Lession01.class); + /** + * GeoTools Quickstart demo application. Prompts the user for a shapefile and displays its + * contents on the screen in a map frame + */ + public static void main(String[] args) throws Exception { + // display a data store file chooser dialog for shapefiles + LOGGER.info( "Quickstart"); + LOGGER.config( "Welcome Developers"); + LOGGER.info("java.util.logging.config.file="+System.getProperty("java.util.logging.config.file")); + File file = JFileDataStoreChooser.showOpenFile("shp", null); + if (file == null) { + return; + } + LOGGER.config("File selected "+file); + + FileDataStore store = FileDataStoreFinder.getDataStore(file); + SimpleFeatureSource featureSource = store.getFeatureSource(); + // 缓存shp文件 + SimpleFeatureSource cachedSource = + DataUtilities.source( + new SpatialIndexFeatureCollection(featureSource.getFeatures())); + // Create a map content and add our shapefile to it + MapContent map = new MapContent(); + map.setTitle("Quickstart"); + + Style style = SLD.createSimpleStyle(featureSource.getSchema()); + Layer layer = new FeatureLayer(cachedSource, style); + map.addLayer(layer); + + // Now display the map + JMapFrame.showMap(map); + } +} diff --git a/src/main/java/org/example/tutorial/Lession02_Feature.java b/src/main/java/org/example/tutorial/Lession02_Feature.java new file mode 100644 index 0000000..05042e7 --- /dev/null +++ b/src/main/java/org/example/tutorial/Lession02_Feature.java @@ -0,0 +1,208 @@ +package org.example.tutorial; + +import org.geotools.api.data.SimpleFeatureSource; +import org.geotools.api.data.SimpleFeatureStore; +import org.geotools.api.data.Transaction; +import org.geotools.api.feature.simple.SimpleFeature; +import org.geotools.api.feature.simple.SimpleFeatureType; +import org.geotools.data.DataUtilities; +import org.geotools.data.DefaultTransaction; +import org.geotools.data.collection.ListFeatureCollection; +import org.geotools.data.shapefile.ShapefileDataStore; +import org.geotools.data.shapefile.ShapefileDataStoreFactory; +import org.geotools.data.simple.SimpleFeatureCollection; +import org.geotools.feature.simple.SimpleFeatureBuilder; +import org.geotools.feature.simple.SimpleFeatureTypeBuilder; +import org.geotools.geometry.jts.JTSFactoryFinder; +import org.geotools.referencing.crs.DefaultGeographicCRS; +import org.geotools.swing.data.JFileDataStoreChooser; +import org.locationtech.jts.geom.Coordinate; +import org.locationtech.jts.geom.GeometryFactory; +import org.locationtech.jts.geom.Point; + +import javax.swing.*; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class Lession02_Feature { + public static void main(String[] args) throws Exception{ + // Set cross-platform look & feel for compatability + UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); + +// File file = JFileDataStoreChooser.showOpenFile("csv", null); +// if (file == null) { +// return; +// } + File file = new File("src\\main\\resources\\public\\data\\location.csv"); + + /* + * We use the DataUtilities class to create a FeatureType that will describe the data in our + * shapefile. + * + * See also the createFeatureType method below for another, more flexible approach. + */ + final SimpleFeatureType TYPE = + DataUtilities.createType( + "Location", + "the_geom:Point:srid=4326," + + // <- the geometry attribute: Point type + "name:String," + + // <- a String attribute + "number:Integer" // a number attribute + ); + System.out.println("TYPE:" + TYPE); + + /* + * A list to collect features as we create them. + */ + List features = new ArrayList<>(); + /* + * 使用 SimpleFeatureBuilder 创建要素 feature + * GeometryFactory will be used to create the geometry attribute of each feature, + * using a Point object for the location. + */ + GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(); + + SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(TYPE); + + try (BufferedReader reader = new BufferedReader(new FileReader(file))) { + /* First line of the data file is the header */ + String line = reader.readLine(); + System.out.println("Header: " + line); + + for (line = reader.readLine(); line != null; line = reader.readLine()) { + if (line.trim().length() > 0) { // skip blank lines + String[] tokens = line.split("\\,"); + + double latitude = Double.parseDouble(tokens[0]); + double longitude = Double.parseDouble(tokens[1]); + String name = tokens[2].trim(); + int number = Integer.parseInt(tokens[3].trim()); + + /* Longitude (= x coord) first ! */ + Point point = geometryFactory.createPoint(new Coordinate(longitude, latitude)); + + featureBuilder.add(point); + featureBuilder.add(name); + featureBuilder.add(number); + SimpleFeature feature = featureBuilder.buildFeature(null); + features.add(feature); + } + } + + + } + /* + * Get an output file name and create the new shapefile + */ + File newFile = getNewShapeFile(file); + + ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory(); + + Map params = new HashMap<>(); + params.put("url", newFile.toURI().toURL()); + params.put("create spatial index", Boolean.TRUE); + + ShapefileDataStore newDataStore = + (ShapefileDataStore) dataStoreFactory.createNewDataStore(params); + /* + * TYPE is used as a template to describe the file contents + */ + newDataStore.createSchema(TYPE); + + + /* + * Write the features to the shapefile + */ + Transaction transaction = new DefaultTransaction("create"); + + String typeName = newDataStore.getTypeNames()[0]; + SimpleFeatureSource featureSource = newDataStore.getFeatureSource(typeName); + SimpleFeatureType SHAPE_TYPE = featureSource.getSchema(); + /* + * The Shapefile format has a couple limitations: + * - "the_geom" is always first, and used for the geometry attribute name + * - "the_geom" must be of type Point, MultiPoint, MuiltiLineString, MultiPolygon + * - Attribute names are limited in length + * - Not all data types are supported (example Timestamp represented as Date) + * + * Each data store has different limitations so check the resulting SimpleFeatureType. + */ + System.out.println("SHAPE:" + SHAPE_TYPE); + + if (featureSource instanceof SimpleFeatureStore) { + SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource; + /* + * SimpleFeatureStore has a method to add features from a + * SimpleFeatureCollection object, so we use the ListFeatureCollection + * class to wrap our list of features. + */ + SimpleFeatureCollection collection = new ListFeatureCollection(TYPE, features); + featureStore.setTransaction(transaction); + try { + featureStore.addFeatures(collection); + transaction.commit(); + } catch (Exception problem) { + problem.printStackTrace(); + transaction.rollback(); + } finally { + transaction.close(); + } + System.exit(0); // success! + } else { + System.out.println(typeName + " does not support read/write access"); + System.exit(1); + } + } + /** + * Prompt the user for the name and path to use for the output shapefile + * + * @param csvFile the input csv file used to create a default shapefile name + * @return name and path for the shapefile as a new File object + */ + private static File getNewShapeFile(File csvFile) { + String path = csvFile.getAbsolutePath(); + String newPath = path.substring(0, path.length() - 4) + ".shp"; + + JFileDataStoreChooser chooser = new JFileDataStoreChooser("shp"); + chooser.setDialogTitle("Save shapefile"); + chooser.setSelectedFile(new File(newPath)); + + int returnVal = chooser.showSaveDialog(null); + + if (returnVal != JFileDataStoreChooser.APPROVE_OPTION) { + // the user cancelled the dialog + System.exit(0); + } + + File newFile = chooser.getSelectedFile(); + if (newFile.equals(csvFile)) { + System.out.println("Error: cannot replace " + csvFile); + System.exit(0); + } + + return newFile; + } + private static SimpleFeatureType createFeatureType() { + + SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); + builder.setName("Location"); + builder.setCRS(DefaultGeographicCRS.WGS84); // <- Coordinate reference system + + // add attributes in order + builder.add("the_geom", Point.class); + builder.length(15).add("Name", String.class); // <- 15 chars width for name field + builder.add("number", Integer.class); + + // build the type + final SimpleFeatureType LOCATION = builder.buildFeatureType(); + + return LOCATION; + } +} diff --git a/src/main/java/org/example/utils/IntersectionBuilder.java b/src/main/java/org/example/utils/IntersectionBuilder.java new file mode 100644 index 0000000..c0a46c2 --- /dev/null +++ b/src/main/java/org/example/utils/IntersectionBuilder.java @@ -0,0 +1,49 @@ +package org.example.utils; + +import java.io.IOException; +import java.util.Map; +import org.geotools.api.data.SimpleFeatureSource; +import org.geotools.api.feature.simple.SimpleFeatureType; +import org.geotools.api.filter.Filter; +import org.geotools.api.filter.FilterFactory; +import org.geotools.factory.CommonFactoryFinder; +import org.geotools.geometry.jts.JTSFactoryFinder; +import org.geotools.grid.GridElement; +import org.geotools.grid.GridFeatureBuilder; +import org.geotools.grid.PolygonElement; +import org.locationtech.jts.geom.Coordinate; +import org.locationtech.jts.geom.Geometry; +import org.locationtech.jts.geom.GeometryFactory; + +public class IntersectionBuilder extends GridFeatureBuilder { + final FilterFactory ff2 = CommonFactoryFinder.getFilterFactory(); + final GeometryFactory gf = JTSFactoryFinder.getGeometryFactory(); + + final SimpleFeatureSource source; + int id = 0; + + public IntersectionBuilder(SimpleFeatureType type, SimpleFeatureSource source) { + super(type); + this.source = source; + } + + public void setAttributes(GridElement el, Map attributes) { + attributes.put("id", ++id); + } + + @Override + public boolean getCreateFeature(GridElement el) { + Coordinate c = ((PolygonElement) el).getCenter(); + Geometry p = gf.createPoint(c); + Filter filter = ff2.intersects(ff2.property("the_geom"), ff2.literal(p)); + boolean result = false; + + try { + result = !source.getFeatures(filter).isEmpty(); + } catch (IOException ex) { + throw new IllegalStateException(ex); + } + + return result; + } +} \ No newline at end of file diff --git a/src/main/resources/public/data/ASTGTMV003_N23E113_dem.tif b/src/main/resources/public/data/ASTGTMV003_N23E113_dem.tif new file mode 100644 index 0000000..a9176b2 Binary files /dev/null and b/src/main/resources/public/data/ASTGTMV003_N23E113_dem.tif differ diff --git a/src/main/resources/public/data/ASTGTM_N23E113S.img b/src/main/resources/public/data/ASTGTM_N23E113S.img new file mode 100644 index 0000000..2eb18ba Binary files /dev/null and b/src/main/resources/public/data/ASTGTM_N23E113S.img differ diff --git a/src/main/resources/public/data/bound1.geojson b/src/main/resources/public/data/bound1.geojson new file mode 100644 index 0000000..cd46705 --- /dev/null +++ b/src/main/resources/public/data/bound1.geojson @@ -0,0 +1,8 @@ +{ +"type": "FeatureCollection", +"name": "bound1", +"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } }, +"features": [ +{ "type": "Feature", "properties": { "id": 1, "name": "1" }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 113.52896835361318, 23.654018962759377 ], [ 113.529270627066524, 23.654027766840539 ], [ 113.529270627066524, 23.654027766840539 ], [ 113.529294104616298, 23.653772448486752 ], [ 113.528977157694356, 23.653763644405586 ], [ 113.52896835361318, 23.654018962759377 ] ] ] ] } } +] +} diff --git a/src/main/resources/public/data/location.csv b/src/main/resources/public/data/location.csv new file mode 100644 index 0000000..f703e6a --- /dev/null +++ b/src/main/resources/public/data/location.csv @@ -0,0 +1,16 @@ +LAT, LON, CITY, NUMBER +46.066667, 11.116667, Trento, 140 +44.9441, -93.0852, St Paul, 125 +13.752222, 100.493889, Bangkok, 150 +45.420833, -75.69, Ottawa, 200 +44.9801, -93.251867, Minneapolis, 350 +46.519833, 6.6335, Lausanne, 560 +48.428611, -123.365556, Victoria, 721 +-33.925278, 18.423889, Cape Town, 550 +-33.859972, 151.211111, Sydney, 436 +41.383333, 2.183333, Barcelona, 914 +39.739167, -104.984722, Denver, 869 +52.95, -1.133333, Nottingham, 800 +45.52, -122.681944, Portland, 840 +37.5667,129.681944,Seoul,473 +50.733992,7.099814,Bonn,700,2016 \ No newline at end of file diff --git a/src/main/resources/public/data/location.dbf b/src/main/resources/public/data/location.dbf new file mode 100644 index 0000000..4f924aa Binary files /dev/null and b/src/main/resources/public/data/location.dbf differ diff --git a/src/main/resources/public/data/location.fix b/src/main/resources/public/data/location.fix new file mode 100644 index 0000000..e9661ca Binary files /dev/null and b/src/main/resources/public/data/location.fix differ diff --git a/src/main/resources/public/data/location.prj b/src/main/resources/public/data/location.prj new file mode 100644 index 0000000..d2e047e --- /dev/null +++ b/src/main/resources/public/data/location.prj @@ -0,0 +1 @@ +GEOGCS["WGS 84", DATUM["World Geodetic System 1984", SPHEROID["WGS 84", 6378137.0, 298.257223563, AUTHORITY["EPSG","7030"]], AUTHORITY["EPSG","6326"]], PRIMEM["Greenwich", 0.0, AUTHORITY["EPSG","8901"]], UNIT["degree", 0.017453292519943295], AXIS["Geodetic latitude", NORTH], AXIS["Geodetic longitude", EAST], AUTHORITY["EPSG","4326"]] \ No newline at end of file diff --git a/src/main/resources/public/data/location.shp b/src/main/resources/public/data/location.shp new file mode 100644 index 0000000..499776a Binary files /dev/null and b/src/main/resources/public/data/location.shp differ diff --git a/src/main/resources/public/data/location.shx b/src/main/resources/public/data/location.shx new file mode 100644 index 0000000..af14b8b Binary files /dev/null and b/src/main/resources/public/data/location.shx differ diff --git a/src/test/java/org/example/AppTest.java b/src/test/java/org/example/AppTest.java new file mode 100644 index 0000000..d5f435d --- /dev/null +++ b/src/test/java/org/example/AppTest.java @@ -0,0 +1,38 @@ +package org.example; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +} diff --git a/target/classes/org/example/CutFillDemo.class b/target/classes/org/example/CutFillDemo.class new file mode 100644 index 0000000..7c57842 Binary files /dev/null and b/target/classes/org/example/CutFillDemo.class differ diff --git a/target/classes/org/example/test/Caclelate.class b/target/classes/org/example/test/Caclelate.class new file mode 100644 index 0000000..98c416b Binary files /dev/null and b/target/classes/org/example/test/Caclelate.class differ diff --git a/target/classes/org/example/test/CreateGrid$1.class b/target/classes/org/example/test/CreateGrid$1.class new file mode 100644 index 0000000..33ea4bf Binary files /dev/null and b/target/classes/org/example/test/CreateGrid$1.class differ diff --git a/target/classes/org/example/test/CreateGrid.class b/target/classes/org/example/test/CreateGrid.class new file mode 100644 index 0000000..811bcd1 Binary files /dev/null and b/target/classes/org/example/test/CreateGrid.class differ diff --git a/target/classes/org/example/tutorial/Lession01.class b/target/classes/org/example/tutorial/Lession01.class new file mode 100644 index 0000000..16b752f Binary files /dev/null and b/target/classes/org/example/tutorial/Lession01.class differ diff --git a/target/classes/org/example/tutorial/Lession02_Feature.class b/target/classes/org/example/tutorial/Lession02_Feature.class new file mode 100644 index 0000000..96e88d8 Binary files /dev/null and b/target/classes/org/example/tutorial/Lession02_Feature.class differ diff --git a/target/classes/org/example/utils/IntersectionBuilder.class b/target/classes/org/example/utils/IntersectionBuilder.class new file mode 100644 index 0000000..b3ea38d Binary files /dev/null and b/target/classes/org/example/utils/IntersectionBuilder.class differ diff --git a/target/classes/public/data/ASTGTMV003_N23E113_dem.tif b/target/classes/public/data/ASTGTMV003_N23E113_dem.tif new file mode 100644 index 0000000..a9176b2 Binary files /dev/null and b/target/classes/public/data/ASTGTMV003_N23E113_dem.tif differ diff --git a/target/classes/public/data/ASTGTM_N23E113S.img b/target/classes/public/data/ASTGTM_N23E113S.img new file mode 100644 index 0000000..2eb18ba Binary files /dev/null and b/target/classes/public/data/ASTGTM_N23E113S.img differ diff --git a/target/classes/public/data/bound1.geojson b/target/classes/public/data/bound1.geojson new file mode 100644 index 0000000..cd46705 --- /dev/null +++ b/target/classes/public/data/bound1.geojson @@ -0,0 +1,8 @@ +{ +"type": "FeatureCollection", +"name": "bound1", +"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } }, +"features": [ +{ "type": "Feature", "properties": { "id": 1, "name": "1" }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 113.52896835361318, 23.654018962759377 ], [ 113.529270627066524, 23.654027766840539 ], [ 113.529270627066524, 23.654027766840539 ], [ 113.529294104616298, 23.653772448486752 ], [ 113.528977157694356, 23.653763644405586 ], [ 113.52896835361318, 23.654018962759377 ] ] ] ] } } +] +} diff --git a/target/classes/public/data/location.csv b/target/classes/public/data/location.csv new file mode 100644 index 0000000..f703e6a --- /dev/null +++ b/target/classes/public/data/location.csv @@ -0,0 +1,16 @@ +LAT, LON, CITY, NUMBER +46.066667, 11.116667, Trento, 140 +44.9441, -93.0852, St Paul, 125 +13.752222, 100.493889, Bangkok, 150 +45.420833, -75.69, Ottawa, 200 +44.9801, -93.251867, Minneapolis, 350 +46.519833, 6.6335, Lausanne, 560 +48.428611, -123.365556, Victoria, 721 +-33.925278, 18.423889, Cape Town, 550 +-33.859972, 151.211111, Sydney, 436 +41.383333, 2.183333, Barcelona, 914 +39.739167, -104.984722, Denver, 869 +52.95, -1.133333, Nottingham, 800 +45.52, -122.681944, Portland, 840 +37.5667,129.681944,Seoul,473 +50.733992,7.099814,Bonn,700,2016 \ No newline at end of file diff --git a/target/classes/public/data/location.dbf b/target/classes/public/data/location.dbf new file mode 100644 index 0000000..4f924aa Binary files /dev/null and b/target/classes/public/data/location.dbf differ diff --git a/target/classes/public/data/location.fix b/target/classes/public/data/location.fix new file mode 100644 index 0000000..e9661ca Binary files /dev/null and b/target/classes/public/data/location.fix differ diff --git a/target/classes/public/data/location.prj b/target/classes/public/data/location.prj new file mode 100644 index 0000000..d2e047e --- /dev/null +++ b/target/classes/public/data/location.prj @@ -0,0 +1 @@ +GEOGCS["WGS 84", DATUM["World Geodetic System 1984", SPHEROID["WGS 84", 6378137.0, 298.257223563, AUTHORITY["EPSG","7030"]], AUTHORITY["EPSG","6326"]], PRIMEM["Greenwich", 0.0, AUTHORITY["EPSG","8901"]], UNIT["degree", 0.017453292519943295], AXIS["Geodetic latitude", NORTH], AXIS["Geodetic longitude", EAST], AUTHORITY["EPSG","4326"]] \ No newline at end of file diff --git a/target/classes/public/data/location.shp b/target/classes/public/data/location.shp new file mode 100644 index 0000000..499776a Binary files /dev/null and b/target/classes/public/data/location.shp differ diff --git a/target/classes/public/data/location.shx b/target/classes/public/data/location.shx new file mode 100644 index 0000000..af14b8b Binary files /dev/null and b/target/classes/public/data/location.shx differ