初始化
This commit is contained in:
parent
764fec8821
commit
28c98e6c09
2
pom.xml
2
pom.xml
@ -250,7 +250,7 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.geotools</groupId>
|
<groupId>org.geotools</groupId>
|
||||||
<artifactId>gt-swing</artifactId>
|
<artifactId>gt-epsg-hsql</artifactId>
|
||||||
<version>${geotools.version}</version>
|
<version>${geotools.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@ -2,13 +2,20 @@ package com.gis3c.spatial.common;/**
|
|||||||
* Created by hukekuan on 17-7-10.
|
* Created by hukekuan on 17-7-10.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import com.vividsolutions.jts.geom.Geometry;
|
||||||
|
import org.geotools.data.DefaultTransaction;
|
||||||
|
import org.geotools.data.Transaction;
|
||||||
import org.geotools.factory.CommonFactoryFinder;
|
import org.geotools.factory.CommonFactoryFinder;
|
||||||
|
import org.geotools.geometry.jts.JTS;
|
||||||
import org.geotools.referencing.CRS;
|
import org.geotools.referencing.CRS;
|
||||||
import org.geotools.referencing.crs.DefaultGeographicCRS;
|
import org.geotools.referencing.crs.DefaultGeographicCRS;
|
||||||
import org.opengis.filter.FilterFactory2;
|
import org.opengis.filter.FilterFactory2;
|
||||||
import org.opengis.referencing.FactoryException;
|
import org.opengis.referencing.FactoryException;
|
||||||
import org.opengis.referencing.NoSuchAuthorityCodeException;
|
import org.opengis.referencing.NoSuchAuthorityCodeException;
|
||||||
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||||
|
import org.opengis.referencing.operation.MathTransform;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author hukekuan
|
* @author hukekuan
|
||||||
@ -24,8 +31,45 @@ public class CRSUtilities {
|
|||||||
if(sridNumber == null || "".equals(sridNumber)){
|
if(sridNumber == null || "".equals(sridNumber)){
|
||||||
return DefaultGeographicCRS.WGS84;
|
return DefaultGeographicCRS.WGS84;
|
||||||
}
|
}
|
||||||
crs = CRS.decode("EPSG:" + sridNumber);
|
crs = CRS.decode("epsg:" + sridNumber);
|
||||||
|
|
||||||
return crs;
|
return crs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成坐标系转变对象
|
||||||
|
* @param rawSridNumber, 如 "4326"
|
||||||
|
* @param goalSridNumber, 如 "4326"
|
||||||
|
* @return
|
||||||
|
* @throws FactoryException
|
||||||
|
*/
|
||||||
|
public static MathTransform MathTransform(String rawSridNumber, String goalSridNumber)
|
||||||
|
throws FactoryException{
|
||||||
|
CoordinateReferenceSystem rawCRS = null;
|
||||||
|
CoordinateReferenceSystem goalCRS = null;
|
||||||
|
if(rawSridNumber == null || "".equals(rawSridNumber)
|
||||||
|
|| goalSridNumber == null || "".equals(goalSridNumber)){
|
||||||
|
throw new IllegalArgumentException("参数输入有误");
|
||||||
|
}
|
||||||
|
rawCRS = GetCRSFromSRID(rawSridNumber);
|
||||||
|
goalCRS = GetCRSFromSRID(goalSridNumber);
|
||||||
|
|
||||||
|
return CRS.findMathTransform(rawCRS, goalCRS, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Geometry CRSTransform(Geometry geometry, MathTransform transform)
|
||||||
|
throws IOException {
|
||||||
|
Geometry resultGeometry = null;
|
||||||
|
Transaction transaction = new DefaultTransaction("Project");
|
||||||
|
try {
|
||||||
|
resultGeometry = JTS.transform(geometry, transform);
|
||||||
|
transaction.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
transaction.rollback();
|
||||||
|
}finally{
|
||||||
|
transaction.close();
|
||||||
|
}
|
||||||
|
return resultGeometry;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -120,7 +120,7 @@ public class FeatureUtilities {
|
|||||||
fjson.writeFeatureCollection(simpleFeatureCollection, writer);
|
fjson.writeFeatureCollection(simpleFeatureCollection, writer);
|
||||||
result = writer.toString();
|
result = writer.toString();
|
||||||
}else {
|
}else {
|
||||||
result="{'type': 'FeatureCollection', 'features': []}";
|
result="{\"type\": \"FeatureCollection\", \"features\": []}";
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@ -4,12 +4,17 @@ import com.vividsolutions.jts.geom.*;
|
|||||||
import com.vividsolutions.jts.io.ParseException;
|
import com.vividsolutions.jts.io.ParseException;
|
||||||
import com.vividsolutions.jts.io.WKTReader;
|
import com.vividsolutions.jts.io.WKTReader;
|
||||||
import com.vividsolutions.jts.io.WKTWriter;
|
import com.vividsolutions.jts.io.WKTWriter;
|
||||||
|
import org.geotools.geometry.jts.JTS;
|
||||||
import org.geotools.geometry.jts.JTSFactoryFinder;
|
import org.geotools.geometry.jts.JTSFactoryFinder;
|
||||||
import net.sf.json.JSONArray;
|
import net.sf.json.JSONArray;
|
||||||
import net.sf.json.JSONObject;
|
import net.sf.json.JSONObject;
|
||||||
import org.geotools.geometry.jts.ReferencedEnvelope;
|
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||||
import org.geotools.referencing.crs.DefaultGeographicCRS;
|
import org.geotools.referencing.crs.DefaultGeographicCRS;
|
||||||
|
import org.opengis.referencing.FactoryException;
|
||||||
|
import org.opengis.referencing.operation.MathTransform;
|
||||||
|
import org.opengis.referencing.operation.TransformException;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -34,12 +39,12 @@ public class GeometryUtilities {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据经纬度生成Point
|
* 根据经纬度生成Point
|
||||||
* @param x
|
* @param lon 经度
|
||||||
* @param y
|
* @param lat 维度
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static Point CreatePoint(double x,double y){
|
public static Point CreatePoint(double lon, double lat){
|
||||||
return geomFactory.createPoint(new Coordinate(x,y));
|
return geomFactory.createPoint(new Coordinate(lat, lon));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -312,4 +317,54 @@ public class GeometryUtilities {
|
|||||||
GeometryCollection gc = GeometryCollection(geometryList);
|
GeometryCollection gc = GeometryCollection(geometryList);
|
||||||
return gc.getEnvelope();
|
return gc.getEnvelope();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成Buffer
|
||||||
|
* @param geometry
|
||||||
|
* @param distance
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Polygon CreateBuffer(Geometry geometry,Double distance){
|
||||||
|
Polygon bufferResult = null;
|
||||||
|
if(geometry == null || distance == null){
|
||||||
|
throw new IllegalArgumentException("参数输入有误");
|
||||||
|
}
|
||||||
|
bufferResult = (Polygon) geometry.buffer(distance, 100);
|
||||||
|
|
||||||
|
return bufferResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Polygon CreateBufferByPoint(Double lon,Double lat,Double distance){
|
||||||
|
Point point = CreatePoint(lon,lat);
|
||||||
|
return CreateBuffer(point,distance);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算两个点之间的距离
|
||||||
|
* @param startPoint
|
||||||
|
* @param endPoint
|
||||||
|
* @return
|
||||||
|
* @throws FactoryException
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public static Double PointDistance(Point startPoint,Point endPoint)
|
||||||
|
throws TransformException, FactoryException {
|
||||||
|
int sridValue;
|
||||||
|
if(startPoint == null || endPoint == null){
|
||||||
|
throw new IllegalArgumentException("参数输入有误");
|
||||||
|
}
|
||||||
|
sridValue = startPoint.getSRID();
|
||||||
|
if(sridValue != endPoint.getSRID()){
|
||||||
|
throw new IllegalArgumentException("坐标系不一致");
|
||||||
|
}
|
||||||
|
if(sridValue == 0){
|
||||||
|
sridValue = 4326;
|
||||||
|
}
|
||||||
|
|
||||||
|
return JTS.orthodromicDistance(
|
||||||
|
startPoint.getCoordinate(),
|
||||||
|
endPoint.getCoordinate(),
|
||||||
|
CRSUtilities.GetCRSFromSRID(String.valueOf(sridValue))
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -102,9 +102,6 @@ public class BaseFeature {
|
|||||||
return featureBuilder.buildFeature(featureIndex, objList.toArray());
|
return featureBuilder.buildFeature(featureIndex, objList.toArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/***************************************************************************************************/
|
/***************************************************************************************************/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -7,11 +7,16 @@ import com.gis3c.ol.service.LayerService;
|
|||||||
import com.gis3c.ol.service.MapService;
|
import com.gis3c.ol.service.MapService;
|
||||||
import com.gis3c.ol.service.SourceService;
|
import com.gis3c.ol.service.SourceService;
|
||||||
import com.gis3c.spatial.common.FeatureUtilities;
|
import com.gis3c.spatial.common.FeatureUtilities;
|
||||||
|
import com.gis3c.spatial.common.GeometryUtilities;
|
||||||
import com.gis3c.spatial.entity.Region;
|
import com.gis3c.spatial.entity.Region;
|
||||||
import com.gis3c.spatial.entity.RegionType;
|
import com.gis3c.spatial.entity.RegionType;
|
||||||
import com.gis3c.spatial.service.RegionService;
|
import com.gis3c.spatial.service.RegionService;
|
||||||
import com.gis3c.spatial.service.TestService;
|
import com.gis3c.spatial.service.TestService;
|
||||||
|
import com.vividsolutions.jts.geom.Coordinate;
|
||||||
|
import com.vividsolutions.jts.geom.Point;
|
||||||
import org.opengis.feature.simple.SimpleFeature;
|
import org.opengis.feature.simple.SimpleFeature;
|
||||||
|
import org.opengis.referencing.FactoryException;
|
||||||
|
import org.opengis.referencing.operation.TransformException;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
|
||||||
@ -20,6 +25,7 @@ import java.util.*;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by hukekuan on 2017/12/14.
|
* Created by hukekuan on 2017/12/14.
|
||||||
*/
|
*/
|
||||||
@ -30,34 +36,14 @@ public class App {
|
|||||||
public static void main(String[] args) throws IllegalAccessException, IOException {
|
public static void main(String[] args) throws IllegalAccessException, IOException {
|
||||||
ApplicationContext context = ApplicationInit();
|
ApplicationContext context = ApplicationInit();
|
||||||
|
|
||||||
// SourceService sourceService = context.getBean(SourceService.class);
|
|
||||||
// LayerService layerService = context.getBean(LayerService.class);
|
|
||||||
// MapService mapService = context.getBean(MapService.class);
|
|
||||||
// TestService testService = context.getBean(TestService.class);
|
|
||||||
RegionService regionService = context.getBean(RegionService.class);
|
|
||||||
|
|
||||||
|
|
||||||
System.out.println(3 & 2);
|
|
||||||
|
|
||||||
// System.out.println(a.compareTo(b));
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Point start = GeometryUtilities.CreatePoint(118.024444,36.802778);
|
||||||
|
Point end = GeometryUtilities.CreatePoint(118.027777,36.759166);
|
||||||
|
try {
|
||||||
|
System.out.println(GeometryUtilities.PointDistance(start,end));
|
||||||
|
} catch (TransformException | FactoryException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// List<Region> regionList = regionService.findRegionsByParentCode("370000");
|
// List<Region> regionList = regionService.findRegionsByParentCode("370000");
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user