Could I ask you to keep email questions to the geotools-gt2-users@... email list. As a volunteer I have limited time and only occasionally get a break to answer questions.
If you are interested in formal assistance a number of organisations, including my employer LISAsoft are in a position to provide support.
As for your question - it is one of the example questions in the geotools training materials. There are two tricks to the answer:
- you need to create a new feature type that allows you to record a point
- you need to use geometry.centroid() when copying from your source feature collection to your target feature collection
For the background needed please see:
On 06/01/2011, at 9:08 AM, bishop k ipigansi wrote:
> I'm displaying a shapefile using geotools library. What I want to do is to determine the centroid of polygon and line features as a point feature instead of just returning lat/long of the centroid. That is the point will have the same attributes and the polygon or line feature except for the geometry column.
> --- On Thu, 16/12/10, Jody Garnett <jody.garnett@...> wrote:
> From: Jody Garnett <jody.garnett@...>
> Subject: Re: [Geotools-gt2-users] geocoding an address using geotools library
> To: "Biken" <ipigancy@...>
> Cc: geotools-gt2-users@...
> Date: Thursday, 16 December, 2010, 23:55
> There are a number of open source geocoders out there; thus far nobody has donated one to the geotools project.
> As for your house number problem; use the line string (of the street); there is a method to determine a percentage along the street (which you can figure out from your other two locations).
> If you need to you can use those other two points to shorten your line.
> Of interest:
> - LinearLocation
> - LineSegment.pointAlong(double segmentLengthFraction)
> - LengthIndexedLine.project( double index );
> There is a breakdown of a similar problem here so you can see the style of programming:
> - http://docs.codehaus.org/display/GEOTDOC/Closest+Point+on+a+Line
> On 17/12/2010, at 1:48 AM, Biken wrote:
> > I have an address table in my Postgis database. The table has the following
> > fields: id, city, street, house_number,address_coordinate. My task is to be
> > able to predict the location(coordinates) of a given address if I have details
> > of just the street name and house number. For example, if I have 3 and 7 house
> > numbers in the same street in the database, then I should be able to perdict
> > the location of house numbers 4 or 5 using the records i already have in my
> > database.
> > I can access the table using getools library as featuresource, but I couldn't
> > figure out how to cary out the above task.
> > I will very much appreciate any help
> > thanks.
> > ------------------------------------------------------------------------------
> > Lotusphere 2011
> > Register now for Lotusphere 2011 and learn how
> > to connect the dots, take your collaborative environment
> > to the next level, and enter the era of Social Business.
> > http://p.sf.net/sfu/lotusphere-d2d
> > _______________________________________________
> > Geotools-gt2-users mailing list
> > Geotools-gt2-users@...
> > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users