Hi all,
I would like to read the data from a shapefile and convert it to other format. Here is my code:
int ii = 0;
Iterator iterator = collection.iterator();
try {
while (iterator.hasNext()) {
Feature feature = (Feature) iterator.next();
System.out.print(feature.getID() + "\t");
Fileout.print(ii + " - " + feature.getID() + "\t");
ii++;
for (int i = 0; i < feature.getNumberOfAttributes(); i++) {
Object attribute = feature.getAttribute(i);
if (!(attribute instanceof Geometry)){
System.out.print(attribute + "\t");
Fileout.print(attribute + "\t");
}
else System.out.print("Geometry \t");
}
System.out.println();
Fileout.println();
}
} finally {
collection.close(iterator);
Fileout.close();
}
And the output of the code above has the format:
gt_bd MULTIPOLYGON (((105.82566795385466 21.036750413334275, ……………………))) 0.0 0.0010 2 §êng Ng• 4 Hïng V¬ng - TrÇn Phó §êng 0.0 0.0 0 0.0 0.0 5 true
But I am interested only in the point value (((105.82566795385466 21.036750413334275, ……………………))) which can obtain by the code: Object attribute = feature.getAttribute(i); The Object is very general. Can I use other object that I can obtain the data separably, for example:
pointAttribute = feature.getAttribute(i).getPoint(); // get the points only
otherAttribute = feature.getAttribute(i).getName(); // get other attributes
……………………………….
Thanks,