## geotools-gt2-users

 [Geotools-gt2-users] finding points in constant interval with the parameter IN meter From: Pete - 2009-02-24 08:57:19 Attachments: Message as HTML ```i'm trying to find the right function for a while now, but i am stuck.... i have a linestring in wgs84 and i want to find the coordinates along the linestring lets say every 50m... I know i can find the distance between two coordinates in meter (JTS.orthodromicDistance) but thats not the one i am looking for hopefully somebody has a solution... thanks ```
 Re: [Geotools-gt2-users] finding points in constant interval with the parameter IN meter From: Michael Bedward - 2009-02-24 09:46:37 ```LengthIndexedLine is your friend... http://tsusiatsoftware.net/jts/javadoc/com/vividsolutions/jts/linearref/LengthIndexedLine.html Michael ```
 Re: [Geotools-gt2-users] finding points in constant interval with the parameter IN meter From: Pete - 2009-02-24 12:45:09 Attachments: Message as HTML ```Hi Michael, thanks for your reply. I think you are referring to the "extractPoint" function. But the function selects the Point between in a fraction between [0,1] and i like to have something like "find the lat/lon position with the distance of 50meter from the beginning" I belive i have to convert my wgs84-linestring to use the extractPoint function the way i want it... but i don't really know how... I found the following code. But even a simple test where i compare the lenght of each linestring fails :-( MathTransform convert = CRS.findMathTransform( DefaultGeographicCRS.WGS84, DefaultGeocentricCRS.CARTESIAN,false ); Geometry lineStringNew = JTS.transform( lineStringOrig, convert ); 2009/2/24 Michael Bedward > LengthIndexedLine is your friend... > > > http://tsusiatsoftware.net/jts/javadoc/com/vividsolutions/jts/linearref/LengthIndexedLine.html > > Michael > ```
 Re: [Geotools-gt2-users] finding points in constant interval with the parameter IN meter From: Michael Bedward - 2009-02-24 23:11:41 ```Hello Pete, > I think you are referring to the "extractPoint" function. But the function > selects the Point between in a fraction between [0,1] No, it takes a distance in whatever units you are using for your geometries. For example, assuming a Cartesian space (and without checking line direction here)... double interval = 50d; double distance = interval; double end = myLine.getEndPoint().x; LengthIndexedLine lil = new LengthIndexedLine(myLine); List points = new ArrayList(); while (true) { p = lil.extractPoint(distance); if (p.x > end) break; points.add(p); distance += interval; } > and i like to have > something like "find the lat/lon position with the distance of 50meter from > the beginning" JTS doesn't know about non-Cartesian geometries like lat-long. You can use lat-long coords and if the distances involved are very small it will be ok, but as they get larger the calculations will become more inaccurate. > I belive i have to convert my wgs84-linestring to use the extractPoint > function the way i want it... but i don't really know how... You are probably best re-projecting your coords into a system that is relevant to the area that you are dealing with for accuracy. Select a projection (e.g. UTM Zone 55S for me here in Sydney) and find it's EPSG code (http://www.epsg-registry.org/). Then one way to reproject your geometry (someone else here will surely point out a more elegant way !) // not showing exception handling here... CoordinateReferenceSystem inCRS = DefaultGeographicCRS.WGS84; // you are using this ? CoordinateReferenceSystem outCRS = CRS.decode( someEPSGCode ); MathTransform in2out = CRS.findMathTransform(inCRS, outCRS); MathTransform out2in = in2out.inverse(); LineString trLine = JTS.transform( latLongLine, in2out ); Hope this helps Michael ```