So here's the snippet:
String geoJson;
File shpFile = ...//the .shp File
shpFile.setReadOnly();
ShapefileDataStore store = new ShapefileDataStore(shpFile.toURI().toURL());
SimpleFeatureSource source = store.getFeatureSource();
SimpleFeatureCollection featureCollection = source.getFeatures();
FeatureJSON fjson = new FeatureJSON();
try (StringWriter writer = new StringWriter()) {
fjson.writeFeatureCollection(featureCollection, writer);
geoJson = writer.toString();
}
2014-08-20 18:41 GMT+01:00 Jody Garnett <jody.garn...@gmail.com>:
> The geojson module has limited documentation here:
>
> * http://docs.geotools.org/latest/userguide/unsupported/geojson.html
>
> The module is still "unsupported" and thus considered experimental. To
> reach supported status a module needs to provide a certain level of
> testing, and include some documentation.
>
> Hopefully you can put the shapefile reading example and the GeoJSON
> writing example together.
>
> You are welcome to share your final code snippet and I can add it to the
> docs on your behalf.
>
> Jody
>
> Jody Garnett
>
>
> On Wed, Aug 20, 2014 at 9:57 AM, Andreas Silva <
> andreas.si...@inovaworks.com> wrote:
>
>> Hi,
>>
>> I found geoTools lib because I need to convert a shape File (.shp, .dbf)
>> into a geoJson.
>>
>> GeoTools seemed the right way to do this, but strange enough, I did not
>> found any example on how to achieve this.
>>
>> I do have the shape files on my file system and I need to convert them
>> into a geoJson structure.
>>
>> I would really appreciate your help with this.
>>
>> Thank you,
>>
>> --
>> Andreas Silva
>> Mobility Specialist
>> Inovaworks Research and Development
>>
>> Av. Eng. Arantes e Oliveira, nº 11, 4º A
>> 1900-221 Olaias
>> Lisboa - Portugal
>>
>> Tel : 21 247 31 34
>> Fax: 21 010 23 09
>> Tel: 91 886 53 68
>>
>>
>> ------------------------------------------------------------------------------
>> Slashdot TV.
>> Video for Nerds. Stuff that matters.
>> http://tv.slashdot.org/
>> _______________________________________________
>> GeoTools-GT2-Users mailing list
>> GeoTools-GT2-Users@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>>
>>
>
--
Andreas Silva
Mobility Specialist
Inovaworks Research and Development
Av. Eng. Arantes e Oliveira, nº 11, 4º A
1900-221 Olaias
Lisboa - Portugal
Tel : 21 247 31 34
Fax: 21 010 23 09
Tel: 91 886 53 68
------------------------------------------------------------------------------
Slashdot TV.
Video for Nerds. Stuff that matters.
http://tv.slashdot.org/
_______________________________________________
GeoTools-GT2-Users mailing list
GeoTools-GT2-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users