geotools和geoserver利用WFS-T通信,insert操作

gjx78251 2012-06-12 10:07:24
本人最近需要利用java平台和geoserver发布的wfs服务通信,开始学习geotools中间件
其中,在学习wfs-t服务是总是报空指针的错误,哪位大哥能不吝赐教下~
具体代码:
package wfsTest;

import java.util.HashMap;
import java.util.Map;


import org.geotools.data.DataStore;
import org.geotools.data.DataStoreFinder;
import org.geotools.data.DataUtilities;
import org.geotools.data.DefaultTransaction;
import org.geotools.data.Transaction;
import org.geotools.data.wfs.v1_0_0.WFSFeatureStore;

import org.geotools.feature.simple.SimpleFeatureBuilder;
import org.geotools.geometry.jts.JTSFactoryFinder;

import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.feature.type.FeatureType;

import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.Point;


public class WFS_T_Test {

/**
* @param args
*/
public static void main(String[] args) throws Exception{
//连接geoserver
String getCapabilities = "http://localhost:8085/geoserver/ows?service=wfs&version=1.0.0&request=GetCapabilities";
Map connectionParameters = new HashMap();
//获取要素
connectionParameters.put("WFSDataStoreFactory:GET_CAPABILITIES_URL", getCapabilities );
DataStore ds = DataStoreFinder.getDataStore(connectionParameters);
FeatureType ft = ds.getSchema("sf:archsites");
WFSFeatureStore fs= (WFSFeatureStore)ds.getFeatureSource("sf:archsites");


Transaction insert = new DefaultTransaction("insert");
fs.setTransaction(insert);


//创建一个feature对象
GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null);
Point point = geometryFactory.createPoint(new Coordinate(32.0600, 118.8563));
SimpleFeatureBuilder simpleFeatureBuilder = new SimpleFeatureBuilder((SimpleFeatureType)ft);

simpleFeatureBuilder.add(point);
simpleFeatureBuilder.add(27);
simpleFeatureBuilder.add("testName111");
SimpleFeature feature = simpleFeatureBuilder.buildFeature(null);

/* SimpleFeatureCollection fc = FeatureCollections.newCollection();
fc.add(feature);
*/
//添加数据并提交事务
//fs.addFeatures(new CollectionFeatureReader(new SimpleFeature[]{feature}));
//fs.addFeatures(fc);
fs.addFeatures( DataUtilities.collection( feature ) );

insert.commit();
}
}

错误信息:Exception in thread "main" java.lang.NullPointerException
at java.net.URI$Parser.parse(Unknown Source)
at java.net.URI.<init>(Unknown Source)
at org.geotools.data.wfs.v1_0_0.WFSTransactionState.commitPost(WFSTransactionState.java:261)
at org.geotools.data.wfs.v1_0_0.WFSTransactionState.commit(WFSTransactionState.java:152)
at org.geotools.data.DefaultTransaction.commit(DefaultTransaction.java:182)
at wfsTest.WFS_T_Test.main(WFS_T_Test.java:78)
...全文
601 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
gjx78251 2012-06-13
  • 打赏
  • 举报
回复
是不是由于geoserver 不支持对shapefile格式的修改?必须要用数据库或者xml文件?

2,143

社区成员

发帖
与我相关
我的任务
社区描述
它是一种特定的十分重要的空间信息系统。它是在计算机硬、软件系统支持下,对整个或部分地球表层(包括大气层)空间中的有关地理分布数据进行采集、储存、管理、运算、分析、显示和描述的技术系统。
社区管理员
  • 地理信息系统
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧