geotools连接SDE获取数据_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > geotools连接SDE获取数据

geotools连接SDE获取数据

 2013/6/19 11:47:24  meijinbo  程序员俱乐部  我要评论(0)
  • 摘要:publicvoidsdeTest(StringcqlPredicate,StringrefGeo){Mapmap=newHashMap();map.put("dbtype","arcsde");map.put("server","127.0.0.1");map.put("port","5151");map.put("instance","sde");map.put("user","test");map.put("password","test")
  • 标签:数据 连接
class="java" name="code">public void sdeTest(String cqlPredicate,String refGeo){
		Map map = new HashMap();
		map.put( "dbtype", "arcsde" );
		map.put( "server", "127.0.0.1" );
		map.put( "port", "5151" );
		map.put( "instance", "sde" );
		map.put( "user", "test" );
		map.put( "password", "test" );
		DataStore dataStore = null;
		try {
			dataStore = DataStoreFinder.getDataStore(map);
			String typeName = "TEST_PG";
			SimpleFeatureType schema = dataStore.getSchema(typeName);
			String geometryAttributeName = schema.getGeometryDescriptor()
					.getLocalName();
			FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(GeoTools.getDefaultHints());
			List<Filter> match = new ArrayList<Filter>();
			if(cqlPredicate!=null){//属性查询条件 like a='1' and b='2'
				Filter filter1 = CQL.toFilter(cqlPredicate);
				match.add(filter1);
			}
			if(refGeo!=null){//空间查询条件 refGeo 是标准的WKT字符串 
				Filter filter2 = ff.contains(ff.property(geometryAttributeName), ff
						.literal(refGeo));
				match.add(filter2);
			}
			Transaction transaction = new DefaultTransaction();
			Filter filter = ff.and(match);//属性空间联合查询
			Query query = new Query(typeName, filter);
//			query.setStartIndex(new Integer(4));
//			query.setMaxFeatures(2);
			SortBy[] sortBy = new SortBy[1];
			//sortBy[0] = ff.sort("NAME", SortOrder.DESCENDING );
			sortBy[0] = ff.sort("ZZJGDM", SortOrder.ASCENDING );
			query.setSortBy(sortBy);
			FeatureReader reader = dataStore.getFeatureReader(query,
					transaction);
			while (reader.hasNext()) {
				Feature feature = reader.next();
				Iterator iterator = feature.getProperties().iterator();
				while (iterator.hasNext()) {
					Property property = (Property) iterator.next();
//					if(!property.getName().getLocalPart().equalsIgnoreCase(geometryAttributeName))
					System.out.print(property.getName() + "="
							+ property.getValue()+"\t");
					String colName = property.getName().getLocalPart();
				}
				System.out.println();
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (CQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			if(dataStore!=null)
			dataStore.dispose();
		}
	}
发表评论
用户名: 匿名