整体更新
This commit is contained in:
parent
e866eca211
commit
f2f97b0eb6
@ -1,14 +1,14 @@
|
||||
package com.gis3c;
|
||||
|
||||
import com.gis3c.entity.GeoCity;
|
||||
import com.gis3c.service.HelloService;
|
||||
import com.gis3c.service.PostGISService;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class App {
|
||||
public static ApplicationContext ContextInit(){
|
||||
@ -20,24 +20,38 @@ public class App {
|
||||
HelloService obj = (HelloService) context.getBean("helloService");
|
||||
PostGISService postGISService = (PostGISService) context.getBean("postGISService");
|
||||
|
||||
List<Map<String,Object>> columns = new ArrayList<>();
|
||||
Map<String,Object> column = new HashMap<>();
|
||||
column.put("columnName","fid");
|
||||
column.put("typeCode",1);
|
||||
columns.add(column);
|
||||
// List<Map<String,Object>> columns = new ArrayList<>();
|
||||
// Map<String,Object> column = new HashMap<>();
|
||||
// column.put("columnName","fid");
|
||||
// column.put("typeCode",1);
|
||||
// columns.add(column);
|
||||
//
|
||||
// column = new HashMap<>();
|
||||
// column.put("columnName","name");
|
||||
// column.put("typeCode",3);
|
||||
// columns.add(column);
|
||||
//
|
||||
// column = new HashMap<>();
|
||||
// column.put("columnName","geom");
|
||||
// column.put("typeCode",91);
|
||||
// columns.add(column);
|
||||
//
|
||||
// postGISService.CommonCreateTable("test","geom",columns);
|
||||
//
|
||||
// System.out.println(obj.SayHello());
|
||||
|
||||
column = new HashMap<>();
|
||||
column.put("columnName","name");
|
||||
column.put("typeCode",3);
|
||||
columns.add(column);
|
||||
Optional<GeoCity> result = postGISService.AllCities().stream()
|
||||
.filter(GeoCity::isDefaut)
|
||||
.skip(3)
|
||||
// .map(GeoCity::getName)
|
||||
// .anyMatch(GeoCity::isZB)
|
||||
// .findAny();
|
||||
.findFirst();
|
||||
// .collect(Collectors.toList());
|
||||
|
||||
column = new HashMap<>();
|
||||
column.put("columnName","geom");
|
||||
column.put("typeCode",91);
|
||||
columns.add(column);
|
||||
|
||||
postGISService.CommonCreateTable("test","geom",columns);
|
||||
|
||||
System.out.println(obj.SayHello());
|
||||
// result.forEach(item->{
|
||||
// System.out.println(item.getName());
|
||||
// });
|
||||
result.ifPresent(item ->System.out.println(item.getName()));
|
||||
}
|
||||
}
|
||||
@ -1,15 +1,35 @@
|
||||
package com.gis3c;
|
||||
|
||||
import com.gis3c.service.HelloService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import com.gis3c.entity.C3Map;
|
||||
import org.geotools.data.FileDataStore;
|
||||
import org.geotools.data.FileDataStoreFinder;
|
||||
import org.geotools.data.simple.SimpleFeatureSource;
|
||||
import org.geotools.map.FeatureLayer;
|
||||
import org.geotools.map.Layer;
|
||||
import org.geotools.styling.SLD;
|
||||
import org.geotools.styling.Style;
|
||||
import org.geotools.swing.JMapFrame;
|
||||
import org.geotools.swing.data.JFileDataStoreChooser;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Created by hukekuan on 2016/12/28.
|
||||
*/
|
||||
public class Main {
|
||||
@Autowired private HelloService helloService;
|
||||
public static void main(String[] args) throws IOException {
|
||||
File file = JFileDataStoreChooser.showOpenFile("shp",null);
|
||||
if(file == null){
|
||||
return;
|
||||
}
|
||||
|
||||
public void Test(){
|
||||
System.out.println(helloService.SayHello());
|
||||
FileDataStore store = FileDataStoreFinder.getDataStore(file);
|
||||
SimpleFeatureSource featureSource = store.getFeatureSource();
|
||||
|
||||
C3Map map = new C3Map();
|
||||
map.setTitle("Quickstart");
|
||||
Style style = SLD.createSimpleStyle(featureSource.getSchema());
|
||||
Layer layer = new FeatureLayer(featureSource,style);
|
||||
map.addLayer(layer);
|
||||
// map.saveImage("D://mapimage//1.jpg",256);
|
||||
|
||||
JMapFrame.showMap(map);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,8 +1,13 @@
|
||||
package com.gis3c.dao;
|
||||
|
||||
import com.gis3c.entity.GeoCity;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface PostGISDao {
|
||||
public void CommonCreateTable(Map<String,Object> tableStructure);
|
||||
public void CreateSpatialIndex(String tableName,String geometryColumn);
|
||||
|
||||
public List<GeoCity> AllCities();
|
||||
}
|
||||
|
||||
@ -1,12 +1,14 @@
|
||||
package com.gis3c.dao.impl;
|
||||
|
||||
import com.gis3c.dao.PostGISDao;
|
||||
import com.gis3c.entity.GeoCity;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.mybatis.spring.support.SqlSessionDaoSupport;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Repository
|
||||
@ -31,4 +33,9 @@ public class PostGISDaoImpl extends SqlSessionDaoSupport implements PostGISDao {
|
||||
param.put("spatialIndexName","sidx_" + tableName +"_" + geometryColumn);
|
||||
getSqlSession().update("PostGISSql.createSpatialIndex",param);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GeoCity> AllCities(){
|
||||
return getSqlSession().selectList("PostGISSql.allCity");
|
||||
}
|
||||
}
|
||||
|
||||
21
src/main/java/com/gis3c/entity/C3Layer.java
Normal file
21
src/main/java/com/gis3c/entity/C3Layer.java
Normal file
@ -0,0 +1,21 @@
|
||||
package com.gis3c.entity;
|
||||
|
||||
import org.geotools.data.FeatureSource;
|
||||
import org.geotools.map.FeatureLayer;
|
||||
import org.geotools.styling.Style;
|
||||
|
||||
public class C3Layer extends FeatureLayer {
|
||||
public C3Layer(FeatureSource featureSource,Style style){
|
||||
super(featureSource,style);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
77
src/main/java/com/gis3c/entity/C3Map.java
Normal file
77
src/main/java/com/gis3c/entity/C3Map.java
Normal file
@ -0,0 +1,77 @@
|
||||
package com.gis3c.entity;
|
||||
|
||||
import com.sun.media.jai.codec.ImageCodec;
|
||||
import com.sun.media.jai.codec.ImageEncoder;
|
||||
import com.sun.media.jai.codec.PNGEncodeParam;
|
||||
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||
import org.geotools.map.MapContent;
|
||||
import org.geotools.renderer.GTRenderer;
|
||||
import org.geotools.renderer.lite.StreamingRenderer;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class C3Map extends MapContent {
|
||||
public C3Map(){
|
||||
super();
|
||||
}
|
||||
|
||||
public void ExportImg(double x1,double y1,double x2,double y2,int width,int height)
|
||||
throws IOException {
|
||||
//设置出图范围
|
||||
ReferencedEnvelope mapArea
|
||||
= new ReferencedEnvelope(x1,x2,y1,y2,this.getCoordinateReferenceSystem());
|
||||
|
||||
//初始化渲染器
|
||||
StreamingRenderer sr = new StreamingRenderer();
|
||||
sr.setMapContent(this);
|
||||
//初始化输出图像
|
||||
BufferedImage bi = new BufferedImage(width,height,BufferedImage.TYPE_INT_BGR);
|
||||
Graphics g = bi.getGraphics();
|
||||
((Graphics2D)g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||
Rectangle rect = new Rectangle(0,0,width,height);
|
||||
|
||||
//绘制地图
|
||||
sr.paint((Graphics2D) g,rect,mapArea);
|
||||
|
||||
//编码图像
|
||||
PNGEncodeParam encodeParam = PNGEncodeParam.getDefaultEncodeParam(bi);
|
||||
if(encodeParam instanceof PNGEncodeParam.Palette){
|
||||
PNGEncodeParam.Palette p = (PNGEncodeParam.Palette) encodeParam;
|
||||
byte[] b = new byte[]{-127};
|
||||
p.setPaletteTransparency(b);
|
||||
}
|
||||
|
||||
//输出图像
|
||||
ImageEncoder encode = ImageCodec.createImageEncoder("PNG",null,encodeParam);
|
||||
encode.encode(bi.getData(),bi.getColorModel());
|
||||
}
|
||||
|
||||
public void saveImage(final String file,final int imageWidth) throws IOException {
|
||||
GTRenderer renderer = new StreamingRenderer();
|
||||
renderer.setMapContent(this);
|
||||
|
||||
ReferencedEnvelope mapBounds
|
||||
= new ReferencedEnvelope(117.45335889533,121.20518244635,35.753480445714,37.557981231236,this.getCoordinateReferenceSystem());
|
||||
// = this.getMaxBounds();
|
||||
|
||||
|
||||
double heightToWidth = mapBounds.getSpan(1)/mapBounds.getSpan(0);
|
||||
Rectangle imageBounds
|
||||
// = new Rectangle(0,0,imageWidth, (int) Math.round(imageWidth*heightToWidth));
|
||||
= new Rectangle(0,0,256, 256);
|
||||
|
||||
BufferedImage image = new BufferedImage(imageBounds.width,imageBounds.height,BufferedImage.TYPE_INT_RGB);
|
||||
|
||||
Graphics2D gr = image.createGraphics();
|
||||
gr.setPaint(Color.WHITE);
|
||||
gr.fill(imageBounds);
|
||||
|
||||
renderer.paint(gr,imageBounds,mapBounds);
|
||||
File fileToSave = new File(file);
|
||||
ImageIO.write(image,"jpeg",fileToSave);
|
||||
}
|
||||
}
|
||||
49
src/main/java/com/gis3c/entity/GeoCity.java
Normal file
49
src/main/java/com/gis3c/entity/GeoCity.java
Normal file
@ -0,0 +1,49 @@
|
||||
package com.gis3c.entity;
|
||||
|
||||
import com.vividsolutions.jts.geom.Polygon;
|
||||
|
||||
public class GeoCity {
|
||||
private String code;
|
||||
private String name;
|
||||
private Polygon geom;
|
||||
|
||||
public boolean isDefaut(){
|
||||
boolean defaulted = false;
|
||||
if(this.code.contains("370")){
|
||||
defaulted = true;
|
||||
}
|
||||
return defaulted;
|
||||
}
|
||||
|
||||
public boolean isZB(){
|
||||
boolean zb = false;
|
||||
if("370300".equals(this.getCode())){
|
||||
zb = true;
|
||||
}
|
||||
return zb;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Polygon getGeom() {
|
||||
return geom;
|
||||
}
|
||||
|
||||
public void setGeom(Polygon geom) {
|
||||
this.geom = geom;
|
||||
}
|
||||
}
|
||||
@ -1,8 +1,12 @@
|
||||
package com.gis3c.service;
|
||||
|
||||
import com.gis3c.entity.GeoCity;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface PostGISService {
|
||||
public void CommonCreateTable(String tableName,String geometryColumn,List<Map<String,Object>> columns);
|
||||
|
||||
public List<GeoCity> AllCities();
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package com.gis3c.service.impl;
|
||||
|
||||
import com.gis3c.dao.PostGISDao;
|
||||
import com.gis3c.entity.GeoCity;
|
||||
import com.gis3c.service.PostGISService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import javax.annotation.Resource;
|
||||
@ -32,4 +33,9 @@ public class PostGISServiceImpl implements PostGISService {
|
||||
postGISDao.CommonCreateTable(tableStructure);
|
||||
postGISDao.CreateSpatialIndex(tableName,geometryColumn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GeoCity> AllCities(){
|
||||
return postGISDao.AllCities();
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,6 +4,11 @@
|
||||
<resultMap id="GeoCityResultMap" type="java.util.HashMap">
|
||||
<result property="geom" column="geom" javaType="Geometry"/>
|
||||
</resultMap>
|
||||
<resultMap id="geoCity" type="com.gis3c.entity.GeoCity">
|
||||
<result column="code" property="code" />
|
||||
<result column="name" property="name" />
|
||||
<result column="geom" property="geom" javaType="Geometry" />
|
||||
</resultMap>
|
||||
<!--创建空间表通用方法-->
|
||||
<update id="commonCreateTable">
|
||||
CREATE TABLE ${tableName}
|
||||
@ -113,12 +118,9 @@
|
||||
delete from ${_parameter}
|
||||
</delete>
|
||||
|
||||
<select id="allCity" resultMap="GeoCityResultMap">
|
||||
select t.stationid,t.subtype,t.geom as geom from station t where ST_Intersects(
|
||||
ST_Buffer(
|
||||
Geography(#{geom,javaType=Geometry}),1000
|
||||
),
|
||||
t.geom
|
||||
)
|
||||
<select id="allCity" resultMap="geoCity">
|
||||
select t."CODE" as code,t."NAME" as name, t.geom
|
||||
from geocity t;
|
||||
--where t."CODE"='370300';
|
||||
</select>
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue
Block a user