| | |
| | | import org.opengis.referencing.crs.CoordinateReferenceSystem; |
| | | import org.springframework.stereotype.Service; |
| | | import org.geotools.referencing.CRS; |
| | | import sun.awt.IconInfo; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.awt.geom.Point2D; |
| | | import java.io.File; |
| | | import java.util.*; |
| | | |
| | |
| | | * 分析线 |
| | | */ |
| | | public void analysisPolyline(AnalysisResultEntity entity, Dataset ds, Geometry geo, int size) { |
| | | /*Double len = geo.Length(); |
| | | |
| | | |
| | | double[] transform = ds.GetGeoTransform(); |
| | | // double rotationX = transform[2]; double rotationY = transform[4] |
| | | double minX = transform[0], pixelWidth = transform[1], maxY = transform[3], pixelHeight = Math.abs(transform[5]); |
| | | |
| | | double buffer = Math.max(pixelWidth, pixelHeight) * size; |
| | | double[] env = new double[4]; |
| | | geo = geo.Buffer(buffer); |
| | | geo.GetEnvelope(env); |
| | | |
| | | int xMinPixel = (int) Math.floor((env[0] - minX) / pixelWidth); |
| | | int yMinPixel = (int) Math.floor((maxY - env[3]) / pixelHeight); |
| | | int xMaxPixel = (int) Math.floor((env[1] - minX) / pixelWidth); |
| | | int yMaxPixel = (int) Math.floor((maxY - env[2]) / pixelHeight); |
| | | double minX = transform[0], pixelWidth = transform[1], maxY = transform[3], pixelHeight = transform[5]; |
| | | |
| | | int bandCount = ds.getRasterCount(); |
| | | int xMin = Math.min(xMinPixel, xMaxPixel); |
| | | int xMax = Math.max(xMinPixel, xMaxPixel); |
| | | int yMin = Math.min(yMinPixel, yMaxPixel); |
| | | int yMax = Math.max(yMinPixel, yMaxPixel); |
| | | |
| | | List<Double> list = new ArrayList<>(); |
| | | for (int y = yMin; y <= yMax; y++) { |
| | | for (int x = xMin; x <= xMax; x++) { |
| | | Geometry point = new Geometry(ogr.wkbPoint); |
| | | point.AddPoint(minX + pixelWidth * x, maxY - pixelHeight * y); |
| | | if (geo.Intersects(point)) { |
| | | for (int i = 1; i <= bandCount; i++) { |
| | | double[] values = new double[1]; |
| | | ds.GetRasterBand(i).ReadRaster(x, y, 1, 1, values); |
| | | list.add(values[0]); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | processResult(list, entity);*/ |
| | | |
| | | //double dis = GeoHelper.getDistance1() |
| | | |
| | | double lineDis = getPolylineDistance(geo); |
| | | double distance = lineDis / Math.max(geo.GetPointCount(), size); |
| | | |
| | | List<double[]> list = getPointsByDistance(geo, distance); |
| | | List<double[]> points = getPointsByDistance(geo, distance); |
| | | for (double[] xy : points) { |
| | | int xPixel = (int) Math.floor((xy[0] - minX) / pixelWidth); |
| | | int yPixel = (int) Math.floor((maxY - xy[1]) / Math.abs(pixelHeight)); |
| | | |
| | | List<Double> vals = new ArrayList<>(); |
| | | for (int i = 1; i <= bandCount; i++) { |
| | | double[] pixelValues = new double[1]; |
| | | ds.GetRasterBand(i).ReadRaster(xPixel, yPixel, 1, 1, pixelValues); |
| | | vals.add(pixelValues[0]); |
| | | } |
| | | entity.addPoint(xy[0], xy[1], vals); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | double[] xy1 = geo.GetPoint(i); |
| | | double[] xy2 = geo.GetPoint(i + 1); |
| | | |
| | | dis += GeoHelper.getDistance2(xy1[0], xy1[1], xy2[0], xy2[1]); |
| | | dis += GeoHelper.getDistance(xy1[0], xy1[1], xy2[0], xy2[1]); |
| | | } |
| | | |
| | | return dis; |
| | |
| | | */ |
| | | private List<double[]> getPointsByDistance(Geometry geo, double distance) { |
| | | List<double[]> list = new ArrayList<>(); |
| | | for (int i = 0, c = geo.GetPointCount() - 1; i < c; i++) { |
| | | |
| | | int c = geo.GetPointCount() - 1; |
| | | for (int i = 0; i < c; i++) { |
| | | double[] xy1 = geo.GetPoint(i); |
| | | double[] xy2 = geo.GetPoint(i + 1); |
| | | list.add(xy1); |
| | | |
| | | double dis = GeoHelper.getDistance2(xy1[0], xy1[1], xy2[0], xy2[1]); |
| | | double lineDis = GeoHelper.getDistance(xy1[0], xy1[1], xy2[0], xy2[1]); |
| | | if (lineDis < distance) { |
| | | continue; |
| | | } |
| | | |
| | | double d = distance; |
| | | double angle = GeoHelper.getAngle(xy1[0], xy1[1], xy2[0], xy2[1]); |
| | | while (d + distance * StaticData.D05 < lineDis) { |
| | | Point2D point = GeoHelper.getPointByDistanceAndAngle(xy1[0], xy1[1], angle, d); |
| | | list.add(new double[]{point.getX(), point.getY()}); |
| | | d += distance; |
| | | } |
| | | } |
| | | |
| | | list.add(geo.GetPoint(c)); |
| | | |
| | | return list; |
| | | } |
| | | } |