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)
...全文
756 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
gjx78251 2012-06-13
  • 打赏
  • 举报
回复
是不是由于geoserver 不支持对shapefile格式的修改?必须要用数据库或者xml文件?
内容概要:本文围绕“考虑用户侧柔性负荷的社区综合能源系统优化调度”展开研究,基于Matlab代码实现,构建了涵盖电、热等多种能源形式耦合的社区级综合能源系统模型。研究重点在于将用户侧具有可调节特性的柔性负荷纳入优化框架,通过建立以经济性和低碳性为目标的优化调度模型,结合YALMIP等优化工具调用Cplex求解器进行求解,在保障用户用能需求的前提下,提升系统对可再生能源的消纳能力,降低综合用能成本,并增强系统运行的灵活性与智能化水平。该研究为社区能源系统的高效、可持续运行提供了可复现的技术方案与仿真验证路径。; 适合人群:具备电力系统、能源系统等相关专业知识基础,熟悉Matlab编程环境与基本优化建模方法的研究生、科研人员及从事能源领域技术研发的工程技术人员。; 使用场景及目标:①用于高校及科研机构开展综合能源系统、需求侧响应、柔性负荷建模等方向的课题研究与算法验证;②为城市社区、产业园区等实际场景的能源管理系统开发提供优化算法支持与案例参考;③帮助研究人员深入掌握多能流协同优化、YALMIP/Cplex应用、日前调度建模及柔性负荷响应机制的代码实现方法。; 阅读建议:建议读者结合提供的Matlab代码实例,逐步搭建并调试仿真模型,重点关注目标函数的设计逻辑、各类物理约束(如功率平衡、设备出力、储能动态等)的数学表达以及柔性负荷参与调度的建模方式,可进一步拓展至不确定性优化、多时间尺度调度等进阶场景进行深化研究。

2,158

社区成员

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

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