Jorge,

It is possible for simple gml but most of the time you need to read the 
shape file then generate your file (csv/xml) programmatically.

here are the codes that I am currently using (just adjust it for your 
needs):

public SimpleFeatureSource readShpAndDbfFile(String shpFilepath) {
     SimpleFeatureSource featureSource = null;
     File shpFile = new File(shpFilepath);

     try {
         if((! shpFile.exists()) && (! shpFile.isFile())) {
             String message = "SHP file is not found";
             log.error(message);
             throw new FileNotFoundException(message);
         }

         Map<String, Serializable> connect = new HashMap<String, 
Serializable>();
         connect.put("url", shpFile.toURI().toURL());
         connect.put("charset", "Windows-31J");

         DataStore dataStore = DataStoreFinder.getDataStore(connect);
         String[] typeNames = dataStore.getTypeNames();
         String typeName = typeNames[0];

         featureSource = dataStore.getFeatureSource(typeName);

     } catch (FileNotFoundException e) {
         log.error(e.getLocalizedMessage());
         e.printStackTrace();
     } catch (MalformedURLException e) {
         log.error(e.getLocalizedMessage());
         e.printStackTrace();
     } catch (IOException e) {
         log.error(e.getLocalizedMessage());
         e.printStackTrace();
     } finally {
         shpFile = null;
     }

     return featureSource;
}

SimpleFeatureSource featureSource = readShpAndDbfFile(shpFilepath);
SimpleFeatureCollection collection = featureSource.getFeatures();
SimpleFeatureIterator iterator = collection.features();

while (iterator.hasNext()) {

     SimpleFeature feature = (SimpleFeature) iterator.next();

     Geometry geometry = (Geometry) feature.getDefaultGeometry();
     ShapeType type = JTSUtilities.findBestGeometryType(geometry);
     if(! type.isPolygonType() && ! type.isLineType() && ! 
type.isPointType()) {
         log.warnLog("warning message here");
         warningCount++;
         break;
     }

     if(geometry.isEmpty()) {
         // TODO empty geometry
         continue;
     }

     //use feature.getProperties() to get the dbf data
}

(2011/10/22 0:17), Jorge Castillo wrote:
> Hi everyone,
>
> I have to develop a GIS application and I need to extract information 
> from a shapefile and put it in a CSV or XML file and I want to know if 
> it's possible using GeoTools.
>
> The information I need is coordenates (x, y) and type of geometry 
> associated with those coordenates.
>
> If the answer is affirmative, wich module do I have to use to get it?
>
> Thanks in advance
>
>
> Jorge Castillo.
>
>
> ------------------------------------------------------------------------------
> The demand for IT networking professionals continues to grow, and the
> demand for specialized networking skills is growing even more rapidly.
> Take a complimentary Learning@Cisco Self-Assessment and learn
> about Cisco certifications, training, and career opportunities.
> http://p.sf.net/sfu/cisco-dev2dev
>
>
> _______________________________________________
> Geotools-gt2-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users


------------------------------------------------------------------------------
The demand for IT networking professionals continues to grow, and the
demand for specialized networking skills is growing even more rapidly.
Take a complimentary Learning@Cisco Self-Assessment and learn 
about Cisco certifications, training, and career opportunities. 
http://p.sf.net/sfu/cisco-dev2dev
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to