问题描述
本人最近需要利用java平台和geoserver发布的wfs服务通信,开始学习geotools中间件其中,在学习wfs-t服务是总是报空指针的错误,哪位大哥能不吝赐教下~具体代码:packagewfsTest;importjava.util.HashMap;importjava.util.Map;importorg.geotools.data.DataStore;importorg.geotools.data.DataStoreFinder;importorg.geotools.data.DataUtilities;importorg.geotools.data.DefaultTransaction;importorg.geotools.data.Transaction;importorg.geotools.data.wfs.v1_0_0.WFSFeatureStore;importorg.geotools.feature.simple.SimpleFeatureBuilder;importorg.geotools.geometry.jts.JTSFactoryFinder;importorg.opengis.feature.simple.SimpleFeature;importorg.opengis.feature.simple.SimpleFeatureType;importorg.opengis.feature.type.FeatureType;importcom.vividsolutions.jts.geom.Coordinate;importcom.vividsolutions.jts.geom.GeometryFactory;importcom.vividsolutions.jts.geom.Point;publicclassWFS_T_Test{/***@paramargs*/publicstaticvoidmain(String[]args)throwsException{//连接geoserverStringgetCapabilities="http://localhost:8085/geoserver/ows?service=wfs&version=1.0.0&request=GetCapabilities";MapconnectionParameters=newHashMap();//获取要素connectionParameters.put("WFSDataStoreFactory:GET_CAPABILITIES_URL",getCapabilities);DataStoreds=DataStoreFinder.getDataStore(connectionParameters);FeatureTypeft=ds.getSchema("sf:archsites");WFSFeatureStorefs=(WFSFeatureStore)ds.getFeatureSource("sf:archsites");Transactioninsert=newDefaultTransaction("insert");fs.setTransaction(insert);//创建一个feature对象GeometryFactorygeometryFactory=JTSFactoryFinder.getGeometryFactory(null);Pointpoint=geometryFactory.createPoint(newCoordinate(32.0600,118.8563));SimpleFeatureBuildersimpleFeatureBuilder=newSimpleFeatureBuilder((SimpleFeatureType)ft);simpleFeatureBuilder.add(point);simpleFeatureBuilder.add(27);simpleFeatureBuilder.add("testName111");SimpleFeaturefeature=simpleFeatureBuilder.buildFeature(null);/*SimpleFeatureCollectionfc=FeatureCollections.newCollection();fc.add(feature);*///添加数据并提交事务//fs.addFeatures(newCollectionFeatureReader(newSimpleFeature[]{feature}));//fs.addFeatures(fc);fs.addFeatures(DataUtilities.collection(feature));insert.commit();}}错误信息:Exceptioninthread"main"java.lang.NullPointerExceptionatjava.net.URI$Parser.parse(UnknownSource)atjava.net.URI.<init>(UnknownSource)atorg.geotools.data.wfs.v1_0_0.WFSTransactionState.commitPost(WFSTransactionState.java:261)atorg.geotools.data.wfs.v1_0_0.WFSTransactionState.commit(WFSTransactionState.java:152)atorg.geotools.data.DefaultTransaction.commit(DefaultTransaction.java:182)atwfsTest.WFS_T_Test.main(WFS_T_Test.java:78)
解决方案
解决方案二:
是不是由于geoserver不支持对shapefile格式的修改?必须要用数据库或者xml文件?