我尝试制作一个项目,使用 GDAL/OGR 将 .mif/.tab 文件中的数据写入数据库。我愿意:
SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(dbFeatureType);
SimpleFeatureCollection collection = FeatureCollections.newCollection();
while (mifReader.hasNext()){
in = (SimpleFeatureImpl) mifReader.next();
SimpleFeature dbFeature = featureBuilder.buildFeature(null);
for(AttributeDescriptor ad : adList){
String name = ad.getLocalName();
Object attrValue;
attrValue = in.getAttribute(name);
if(attrValue instanceof String){
String string3 = new String((attrValue.toString()).getBytes("ISO-8859-1"), "cp1251");
if(name.trim().equalsIgnoreCase(kadname.trim())){
dbFeature.setAttribute("kadnum", string3);
}
}
if (attrValue instanceof Geometry){
idn++;
com.vividsolutions.jts.geom.Geometry geom = (Geometry) in.getAttribute(name);
dbFeature.setAttribute("id", idn);
System.out.println("after insrt="+idn);
dbFeature.setAttribute("deleted", deleted);
dbFeature.setAttribute("the_geom", geom);
dbFeature.setAttribute("status_id", status_id);
}
collection.add(dbFeature);
}
}
它来自 .mid 文件的简单数据:
__id_|___kadnum_____
3,"66:2:00:88 951"
4,"66:2:00:88 952"
5,"66:2:00:88 954"
在分贝我得到这个:
我的数据是 2-4 行。您会看到我得到了增量变量idn
并将其放入属性中id
。从 .mid 中取出一个kadnum
并将其放入属性中kadnum
。
它很好,但在 bd 中我得到的行顺序错误。我的意思是具有属性的元素kadnum=66:2:00:88 951
将位于 db 的第二行,但它位于第 4 行。
这意味着我要将集合中项目的顺序更改为相反的顺序。它的正确解决方案?以及如何做到这一点?或者GDAL可以自己做吗?
更新
我有:
SimplePropertyImpl in =(SimpleFeatureImpl) mifReader.next();
我尝试:
in.getProperty("id").getName() ;
我没有得到一个 PropertyName 我得到一个字符串。我做错了什么?