我嘗試使用GDAL/OGR將數據從.mif/.tab文件寫入數據庫。我做的:如何在Java中使用集合?
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"
,用dB我得到這個:
我的數據是2-4行。你看到我得到增量變量idn
,並把它放在屬性id
。從.mid中取出kadnum
,並將其置於屬性kadnum
中。
很好,但在BD我得到錯誤的順序行。我的意思是屬性爲kadnum=66:2:00:88 951
的元素會在db的第二行,但在第四行。
它的意思是我會改變集合中物品的順序到相反的。它的權利解決?以及如何做到這一點?或GDAL可以自己做到這一點?
UPDATE
我:
SimplePropertyImpl in =(SimpleFeatureImpl) mifReader.next();
我嘗試:
in.getProperty("id").getName() ;
,我不得到一個屬性名,我得到的字符串。我做錯了什麼?
數據庫通常不保證行按特定順序存儲。如果您想按特定順序從數據庫中獲取行,請在SQL查詢中使用「ORDER BY」子句。 – Jesper