## geotools-gt2-users

 [Geotools-gt2-users] affine transformation From: tommaso - 2010-08-18 21:27:02 Attachments: Message as HTML ```Hallo List, I would like to perform some geometry transformations on polygons, i.e rotate about a point, scale and translate. So I create the polygon: import com.vividsolutions.jts.geom.Coordinate import org.geotools.geometry.jts.JTSFactoryFinder import com.vividsolutions.jts.geom.GeometryFactory import com.vividsolutions.jts.geom.LinearRing import com.vividsolutions.jts.geom.Polygon GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory( null ); Coordinate[] coords = [new Coordinate(0, 0), new Coordinate(2, 0), new Coordinate(2, 2), new Coordinate(0, 2), new Coordinate(0, 0)] LinearRing ring = new LinearRing(coords, geometryFactory) Polygon polygon = geometryFactory.createPolygon(ring) I guess I have to use AffineTransform (com.vividsolutions.jts.geom.util.AffineTransformation ?) but I don't know exactly how. A code example or a link to a tutorial were very appreciated. Cheers, Tom ```
 Re: [Geotools-gt2-users] affine transformation From: andrea antonello - 2010-08-18 22:16:29 ```Hi Tommaso, the easiest way to do a rotation for example is: Coordinate ancorPoint = ...; AffineTransform affineTransform = AffineTransform.getRotateInstance(angleRad, ancorPoint.x, ancorPoint.y); MathTransform mathTransform = new AffineTransform2D(affineTransform); Point point = ...point to rotate; Geometry rotatedPoint = JTS.transform(point, mathTransform); Where point can be any geometry. Does that help? Ciao Andrea On Wed, Aug 18, 2010 at 11:26 PM, tommaso wrote: > Hallo List, > > I would like to perform some geometry transformations on polygons, i.e > rotate about a point, scale and translate. > > So I create the polygon: > > import com.vividsolutions.jts.geom.Coordinate > import org.geotools.geometry.jts.JTSFactoryFinder > import com.vividsolutions.jts.geom.GeometryFactory > import com.vividsolutions.jts.geom.LinearRing > import com.vividsolutions.jts.geom.Polygon > >         GeometryFactory geometryFactory = > JTSFactoryFinder.getGeometryFactory( null ); > >         Coordinate[] coords  = [new Coordinate(0, 0), new Coordinate(2, 0), > new Coordinate(2, 2), new Coordinate(0, 2), new Coordinate(0, 0)] >         LinearRing ring = new LinearRing(coords, geometryFactory) >         Polygon polygon = geometryFactory.createPolygon(ring) > > I guess I have to use AffineTransform > (com.vividsolutions.jts.geom.util.AffineTransformation ?) but I don't know > exactly how. > A code example or a link to a tutorial were very appreciated. > > Cheers, > Tom > ------------------------------------------------------------------------------ > This SF.net email is sponsored by > > Make an app they can't live without > Enter the BlackBerry Developer Challenge > http://p.sf.net/sfu/RIM-dev2dev > _______________________________________________ > Geotools-gt2-users mailing list > Geotools-gt2-users@... > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users > > ```
 Re: [Geotools-gt2-users] affine transformation From: Jody Garnett - 2010-08-19 00:35:31 ```Thanks; Added your example to this page: - http://docs.codehaus.org/display/GEOTDOC/02+JTS+Utility+Class Jody On 19/08/2010, at 8:15 AM, andrea antonello wrote: > Coordinate ancorPoint = ...; > AffineTransform affineTransform = > AffineTransform.getRotateInstance(angleRad, ancorPoint.x, > ancorPoint.y); > MathTransform mathTransform = new AffineTransform2D(affineTransform); > > Point point = ...point to rotate; > Geometry rotatedPoint = JTS.transform(point, mathTransform); ```
 Re: [Geotools-gt2-users] affine transformation From: tommaso - 2010-08-19 09:19:42 Attachments: Message as HTML ```Hi Andrea, Hi Christian this works, thank you very much for the support. Ciao, Tommaso On Thu, 2010-08-19 at 00:15 +0200, andrea antonello wrote: > Hi Tommaso, > the easiest way to do a rotation for example is: > > Coordinate ancorPoint = ...; > AffineTransform affineTransform = > AffineTransform.getRotateInstance(angleRad, ancorPoint.x, > ancorPoint.y); > MathTransform mathTransform = new AffineTransform2D(affineTransform); > > Point point = ...point to rotate; > Geometry rotatedPoint = JTS.transform(point, mathTransform); > > Where point can be any geometry. > > Does that help? > > Ciao > Andrea > > > On Wed, Aug 18, 2010 at 11:26 PM, tommaso wrote: > > Hallo List, > > > > I would like to perform some geometry transformations on polygons, i.e > > rotate about a point, scale and translate. > > > > So I create the polygon: > > > > import com.vividsolutions.jts.geom.Coordinate > > import org.geotools.geometry.jts.JTSFactoryFinder > > import com.vividsolutions.jts.geom.GeometryFactory > > import com.vividsolutions.jts.geom.LinearRing > > import com.vividsolutions.jts.geom.Polygon > > > > GeometryFactory geometryFactory = > > JTSFactoryFinder.getGeometryFactory( null ); > > > > Coordinate[] coords = [new Coordinate(0, 0), new Coordinate(2, 0), > > new Coordinate(2, 2), new Coordinate(0, 2), new Coordinate(0, 0)] > > LinearRing ring = new LinearRing(coords, geometryFactory) > > Polygon polygon = geometryFactory.createPolygon(ring) > > > > I guess I have to use AffineTransform > > (com.vividsolutions.jts.geom.util.AffineTransformation ?) but I don't know > > exactly how. > > A code example or a link to a tutorial were very appreciated. > > > > Cheers, > > Tom > > ------------------------------------------------------------------------------ > > This SF.net email is sponsored by > > > > Make an app they can't live without > > Enter the BlackBerry Developer Challenge > > http://p.sf.net/sfu/RIM-dev2dev > > _______________________________________________ > > Geotools-gt2-users mailing list > > Geotools-gt2-users@... > > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users > > > > ```
 Re: [Geotools-gt2-users] affine transformation From: - 2010-08-19 03:01:59 ```Some mathematical basics here. An affine transform is a powerful mechanism to transform coordinates. To get the new coordinates x' and y', the following calculation is done. [ x'] [ m00 m01 m02 ] [ x ] [ m00x + m01y + m02 ] [ y'] = [ m10 m11 m12 ] [ y ] = [ m10x + m11y + m12 ] [ 1 ] [ 0 0 1 ] [ 1 ] [ 1 ] A simple example: if you want to shift a point 5 units on the x axis and -7 units at the y axis, the following matrix is needed [ 1 0 5 ] [ 0 1 -7 ] [ 0 0 1 ] Of course, you can say this is easy, x'=x+5 and y'=y-7 would do the same. Another one, lets do some scaling, say factor 3 [ 3 0 0 ] [ 0 3 0 ] [ 0 0 1 ] This is easy too, x'=x*3 and y'=y*3 would the job. The power of affine transforms is that you can combine multiple matrices into a single one, doing a set of individual transformations within one step. There is a java method "concatenate(AffineTransform)" for the AffineTransform class. But be careful, given 3 transformatons A,B,C and you want to combine them in this order, you have to go from right to left. C concatenate B concatenate A will give you the expected result. A mapping from world coordinates to pixel coordinates needs some operations but can be done within one affine transformation. The second powerful feature is that you can create an inverse transform (Method createInverse), which will do the mapping in the other direction out of the box. Believe me, if you are used to use AffineTransform objects, you will use them forever. Hope this helps Cheers Christian Quoting andrea antonello : > Hi Tommaso, > the easiest way to do a rotation for example is: > > Coordinate ancorPoint = ...; > AffineTransform affineTransform = > AffineTransform.getRotateInstance(angleRad, ancorPoint.x, > ancorPoint.y); > MathTransform mathTransform = new AffineTransform2D(affineTransform); > > Point point = ...point to rotate; > Geometry rotatedPoint = JTS.transform(point, mathTransform); > > Where point can be any geometry. > > Does that help? > > Ciao > Andrea > > > On Wed, Aug 18, 2010 at 11:26 PM, tommaso wrote: >> Hallo List, >> >> I would like to perform some geometry transformations on polygons, i.e >> rotate about a point, scale and translate. >> >> So I create the polygon: >> >> import com.vividsolutions.jts.geom.Coordinate >> import org.geotools.geometry.jts.JTSFactoryFinder >> import com.vividsolutions.jts.geom.GeometryFactory >> import com.vividsolutions.jts.geom.LinearRing >> import com.vividsolutions.jts.geom.Polygon >> >>         GeometryFactory geometryFactory = >> JTSFactoryFinder.getGeometryFactory( null ); >> >>         Coordinate[] coords  = [new Coordinate(0, 0), new Coordinate(2, 0), >> new Coordinate(2, 2), new Coordinate(0, 2), new Coordinate(0, 0)] >>         LinearRing ring = new LinearRing(coords, geometryFactory) >>         Polygon polygon = geometryFactory.createPolygon(ring) >> >> I guess I have to use AffineTransform >> (com.vividsolutions.jts.geom.util.AffineTransformation ?) but I don't know >> exactly how. >> A code example or a link to a tutorial were very appreciated. >> >> Cheers, >> Tom >> ------------------------------------------------------------------------------ >> This SF.net email is sponsored by >> >> Make an app they can't live without >> Enter the BlackBerry Developer Challenge >> http://p.sf.net/sfu/RIM-dev2dev >> _______________________________________________ >> Geotools-gt2-users mailing list >> Geotools-gt2-users@... >> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users >> >> > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by > > Make an app they can't live without > Enter the BlackBerry Developer Challenge > http://p.sf.net/sfu/RIM-dev2dev > _______________________________________________ > Geotools-gt2-users mailing list > Geotools-gt2-users@... > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users > ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. ```
 Re: [Geotools-gt2-users] affine transformation From: Jody Garnett - 2010-08-19 04:01:05 ```You may wish to add some of that to the wiki page :-) I will note if you don't like math, you can just use the methods of the AffineTransform object. Jody On Thu, Aug 19, 2010 at 1:01 PM, wrote: > > Some mathematical basics here. > An affine transform is a powerful mechanism to transform coordinates. > To get the new coordinates x' and y', the following calculation is done. > > [ x']   [  m00  m01  m02  ] [ x ]   [ m00x + m01y + m02 ] > [ y'] = [  m10  m11  m12  ] [ y ] = [ m10x + m11y + m12 ] > [ 1 ]   [   0    0    1   ] [ 1 ]   [         1         ] > > A simple example: > if you want to shift a point 5 units on the x axis and -7 units at the > y axis, the following matrix is needed > > [  1    0  5  ] > [  0    1  -7  ] > [  0    0  1   ] > > Of course, you can say this is easy, x'=x+5 and y'=y-7 would do the same. > > Another one, lets do some scaling, say factor 3 > > [  3    0  0 ] > [  0    3  0  ] > [  0    0  1  ] > > This is easy too, x'=x*3 and y'=y*3 would the job. > > The power of affine transforms is that you can combine multiple > matrices into a single one, doing a set of individual transformations > within one step. There is a java method "concatenate(AffineTransform)" > for the AffineTransform class. But be careful, given 3 transformatons > A,B,C and you want to combine them in this order, you have to go from > right to left. > C concatenate B concatenate A will give you the expected result. > > A mapping from world coordinates to pixel coordinates needs some > operations but can be done within one affine transformation. > > The second powerful feature is that you can create an inverse > transform (Method createInverse), which will do the mapping in the > other direction out of the box. > > Believe me, if you are used to use AffineTransform objects, you will > use them forever. > > Hope this helps > Cheers > Christian > > > > > > > > > > > > > > > > > Quoting andrea antonello : > >> Hi Tommaso, >> the easiest way to do a rotation for example is: >> >> Coordinate ancorPoint = ...; >> AffineTransform affineTransform = >> AffineTransform.getRotateInstance(angleRad, ancorPoint.x, >> ancorPoint.y); >> MathTransform mathTransform = new AffineTransform2D(affineTransform); >> >> Point point = ...point to rotate; >> Geometry rotatedPoint = JTS.transform(point, mathTransform); >> >> Where point can be any geometry. >> >> Does that help? >> >> Ciao >> Andrea >> >> >> On Wed, Aug 18, 2010 at 11:26 PM, tommaso wrote: >>> Hallo List, >>> >>> I would like to perform some geometry transformations on polygons, i.e >>> rotate about a point, scale and translate. >>> >>> So I create the polygon: >>> >>> import com.vividsolutions.jts.geom.Coordinate >>> import org.geotools.geometry.jts.JTSFactoryFinder >>> import com.vividsolutions.jts.geom.GeometryFactory >>> import com.vividsolutions.jts.geom.LinearRing >>> import com.vividsolutions.jts.geom.Polygon >>> >>>         GeometryFactory geometryFactory = >>> JTSFactoryFinder.getGeometryFactory( null ); >>> >>>         Coordinate[] coords  = [new Coordinate(0, 0), new Coordinate(2, 0), >>> new Coordinate(2, 2), new Coordinate(0, 2), new Coordinate(0, 0)] >>>         LinearRing ring = new LinearRing(coords, geometryFactory) >>>         Polygon polygon = geometryFactory.createPolygon(ring) >>> >>> I guess I have to use AffineTransform >>> (com.vividsolutions.jts.geom.util.AffineTransformation ?) but I don't know >>> exactly how. >>> A code example or a link to a tutorial were very appreciated. >>> >>> Cheers, >>> Tom >>> ------------------------------------------------------------------------------ >>> This SF.net email is sponsored by >>> >>> Make an app they can't live without >>> Enter the BlackBerry Developer Challenge >>> http://p.sf.net/sfu/RIM-dev2dev >>> _______________________________________________ >>> Geotools-gt2-users mailing list >>> Geotools-gt2-users@... >>> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users >>> >>> >> >> ------------------------------------------------------------------------------ >> This SF.net email is sponsored by >> >> Make an app they can't live without >> Enter the BlackBerry Developer Challenge >> http://p.sf.net/sfu/RIM-dev2dev >> _______________________________________________ >> Geotools-gt2-users mailing list >> Geotools-gt2-users@... >> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users >> > > > > ---------------------------------------------------------------- > This message was sent using IMP, the Internet Messaging Program. > > > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by > > Make an app they can't live without > Enter the BlackBerry Developer Challenge > http://p.sf.net/sfu/RIM-dev2dev > _______________________________________________ > Geotools-gt2-users mailing list > Geotools-gt2-users@... > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users > ```
 Re: [Geotools-gt2-users] affine transformation From: - 2010-08-19 07:02:09 ```Quoting Jody Garnett : > You may wish to add some of that to the wiki page :-) I will put it on my todo list, at the moment I am learning for an exam in cryptology, this is mathematical hardcore, unbelievable. > > I will note if you don't like math, you can just use the methods of > the AffineTransform object. Of course you can, but using AffineTransform for simple operations is an overkill. The benefits arise if you use concatenate/createInverse for a set of operations in a predefined order. The mapping of world coords to pixel coords and vice versa is a very good example for this. > > Jody > > > On Thu, Aug 19, 2010 at 1:01 PM, wrote: >> >> Some mathematical basics here. >> An affine transform is a powerful mechanism to transform coordinates. >> To get the new coordinates x' and y', the following calculation is done. >> >> [ x']   [  m00  m01  m02  ] [ x ]   [ m00x + m01y + m02 ] >> [ y'] = [  m10  m11  m12  ] [ y ] = [ m10x + m11y + m12 ] >> [ 1 ]   [   0    0    1   ] [ 1 ]   [         1         ] >> >> A simple example: >> if you want to shift a point 5 units on the x axis and -7 units at the >> y axis, the following matrix is needed >> >> [  1    0  5  ] >> [  0    1  -7  ] >> [  0    0  1   ] >> >> Of course, you can say this is easy, x'=x+5 and y'=y-7 would do the same. >> >> Another one, lets do some scaling, say factor 3 >> >> [  3    0  0 ] >> [  0    3  0  ] >> [  0    0  1  ] >> >> This is easy too, x'=x*3 and y'=y*3 would the job. >> >> The power of affine transforms is that you can combine multiple >> matrices into a single one, doing a set of individual transformations >> within one step. There is a java method "concatenate(AffineTransform)" >> for the AffineTransform class. But be careful, given 3 transformatons >> A,B,C and you want to combine them in this order, you have to go from >> right to left. >> C concatenate B concatenate A will give you the expected result. >> >> A mapping from world coordinates to pixel coordinates needs some >> operations but can be done within one affine transformation. >> >> The second powerful feature is that you can create an inverse >> transform (Method createInverse), which will do the mapping in the >> other direction out of the box. >> >> Believe me, if you are used to use AffineTransform objects, you will >> use them forever. >> >> Hope this helps >> Cheers >> Christian >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> Quoting andrea antonello : >> >>> Hi Tommaso, >>> the easiest way to do a rotation for example is: >>> >>> Coordinate ancorPoint = ...; >>> AffineTransform affineTransform = >>> AffineTransform.getRotateInstance(angleRad, ancorPoint.x, >>> ancorPoint.y); >>> MathTransform mathTransform = new AffineTransform2D(affineTransform); >>> >>> Point point = ...point to rotate; >>> Geometry rotatedPoint = JTS.transform(point, mathTransform); >>> >>> Where point can be any geometry. >>> >>> Does that help? >>> >>> Ciao >>> Andrea >>> >>> >>> On Wed, Aug 18, 2010 at 11:26 PM, tommaso wrote: >>>> Hallo List, >>>> >>>> I would like to perform some geometry transformations on polygons, i.e >>>> rotate about a point, scale and translate. >>>> >>>> So I create the polygon: >>>> >>>> import com.vividsolutions.jts.geom.Coordinate >>>> import org.geotools.geometry.jts.JTSFactoryFinder >>>> import com.vividsolutions.jts.geom.GeometryFactory >>>> import com.vividsolutions.jts.geom.LinearRing >>>> import com.vividsolutions.jts.geom.Polygon >>>> >>>>         GeometryFactory geometryFactory = >>>> JTSFactoryFinder.getGeometryFactory( null ); >>>> >>>>         Coordinate[] coords  = [new Coordinate(0, 0), new >>>> Coordinate(2, 0), >>>> new Coordinate(2, 2), new Coordinate(0, 2), new Coordinate(0, 0)] >>>>         LinearRing ring = new LinearRing(coords, geometryFactory) >>>>         Polygon polygon = geometryFactory.createPolygon(ring) >>>> >>>> I guess I have to use AffineTransform >>>> (com.vividsolutions.jts.geom.util.AffineTransformation ?) but I don't know >>>> exactly how. >>>> A code example or a link to a tutorial were very appreciated. >>>> >>>> Cheers, >>>> Tom >>>> ------------------------------------------------------------------------------ >>>> This SF.net email is sponsored by >>>> >>>> Make an app they can't live without >>>> Enter the BlackBerry Developer Challenge >>>> http://p.sf.net/sfu/RIM-dev2dev >>>> _______________________________________________ >>>> Geotools-gt2-users mailing list >>>> Geotools-gt2-users@... >>>> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users >>>> >>>> >>> >>> ------------------------------------------------------------------------------ >>> This SF.net email is sponsored by >>> >>> Make an app they can't live without >>> Enter the BlackBerry Developer Challenge >>> http://p.sf.net/sfu/RIM-dev2dev >>> _______________________________________________ >>> Geotools-gt2-users mailing list >>> Geotools-gt2-users@... >>> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users >>> >> >> >> >> ---------------------------------------------------------------- >> This message was sent using IMP, the Internet Messaging Program. >> >> >> >> ------------------------------------------------------------------------------ >> This SF.net email is sponsored by >> >> Make an app they can't live without >> Enter the BlackBerry Developer Challenge >> http://p.sf.net/sfu/RIM-dev2dev >> _______________________________________________ >> Geotools-gt2-users mailing list >> Geotools-gt2-users@... >> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users >> > ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. ```
 Re: [Geotools-gt2-users] affine transformation From: - 2010-09-14 06:14:37 ```Hi Jody, after doing my exams there is time for adding some mathematical basics about Affine Transforms to the WIKI. 1) Do you still want me to add these concepts to the WIKI ? 2) Where would be the best place ? Cheers Christian Quoting Jody Garnett : > You may wish to add some of that to the wiki page :-) > > I will note if you don't like math, you can just use the methods of > the AffineTransform object. > > Jody > > > On Thu, Aug 19, 2010 at 1:01 PM, wrote: >> >> Some mathematical basics here. >> An affine transform is a powerful mechanism to transform coordinates. >> To get the new coordinates x' and y', the following calculation is done. >> >> [ x']   [  m00  m01  m02  ] [ x ]   [ m00x + m01y + m02 ] >> [ y'] = [  m10  m11  m12  ] [ y ] = [ m10x + m11y + m12 ] >> [ 1 ]   [   0    0    1   ] [ 1 ]   [         1         ] >> >> A simple example: >> if you want to shift a point 5 units on the x axis and -7 units at the >> y axis, the following matrix is needed >> >> [  1    0  5  ] >> [  0    1  -7  ] >> [  0    0  1   ] >> >> Of course, you can say this is easy, x'=x+5 and y'=y-7 would do the same. >> >> Another one, lets do some scaling, say factor 3 >> >> [  3    0  0 ] >> [  0    3  0  ] >> [  0    0  1  ] >> >> This is easy too, x'=x*3 and y'=y*3 would the job. >> >> The power of affine transforms is that you can combine multiple >> matrices into a single one, doing a set of individual transformations >> within one step. There is a java method "concatenate(AffineTransform)" >> for the AffineTransform class. But be careful, given 3 transformatons >> A,B,C and you want to combine them in this order, you have to go from >> right to left. >> C concatenate B concatenate A will give you the expected result. >> >> A mapping from world coordinates to pixel coordinates needs some >> operations but can be done within one affine transformation. >> >> The second powerful feature is that you can create an inverse >> transform (Method createInverse), which will do the mapping in the >> other direction out of the box. >> >> Believe me, if you are used to use AffineTransform objects, you will >> use them forever. >> >> Hope this helps >> Cheers >> Christian >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> Quoting andrea antonello : >> >>> Hi Tommaso, >>> the easiest way to do a rotation for example is: >>> >>> Coordinate ancorPoint = ...; >>> AffineTransform affineTransform = >>> AffineTransform.getRotateInstance(angleRad, ancorPoint.x, >>> ancorPoint.y); >>> MathTransform mathTransform = new AffineTransform2D(affineTransform); >>> >>> Point point = ...point to rotate; >>> Geometry rotatedPoint = JTS.transform(point, mathTransform); >>> >>> Where point can be any geometry. >>> >>> Does that help? >>> >>> Ciao >>> Andrea >>> >>> >>> On Wed, Aug 18, 2010 at 11:26 PM, tommaso wrote: >>>> Hallo List, >>>> >>>> I would like to perform some geometry transformations on polygons, i.e >>>> rotate about a point, scale and translate. >>>> >>>> So I create the polygon: >>>> >>>> import com.vividsolutions.jts.geom.Coordinate >>>> import org.geotools.geometry.jts.JTSFactoryFinder >>>> import com.vividsolutions.jts.geom.GeometryFactory >>>> import com.vividsolutions.jts.geom.LinearRing >>>> import com.vividsolutions.jts.geom.Polygon >>>> >>>>         GeometryFactory geometryFactory = >>>> JTSFactoryFinder.getGeometryFactory( null ); >>>> >>>>         Coordinate[] coords  = [new Coordinate(0, 0), new >>>> Coordinate(2, 0), >>>> new Coordinate(2, 2), new Coordinate(0, 2), new Coordinate(0, 0)] >>>>         LinearRing ring = new LinearRing(coords, geometryFactory) >>>>         Polygon polygon = geometryFactory.createPolygon(ring) >>>> >>>> I guess I have to use AffineTransform >>>> (com.vividsolutions.jts.geom.util.AffineTransformation ?) but I don't know >>>> exactly how. >>>> A code example or a link to a tutorial were very appreciated. >>>> >>>> Cheers, >>>> Tom >>>> ------------------------------------------------------------------------------ >>>> This SF.net email is sponsored by >>>> >>>> Make an app they can't live without >>>> Enter the BlackBerry Developer Challenge >>>> http://p.sf.net/sfu/RIM-dev2dev >>>> _______________________________________________ >>>> Geotools-gt2-users mailing list >>>> Geotools-gt2-users@... >>>> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users >>>> >>>> >>> >>> ------------------------------------------------------------------------------ >>> This SF.net email is sponsored by >>> >>> Make an app they can't live without >>> Enter the BlackBerry Developer Challenge >>> http://p.sf.net/sfu/RIM-dev2dev >>> _______________________________________________ >>> Geotools-gt2-users mailing list >>> Geotools-gt2-users@... >>> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users >>> >> >> >> >> ---------------------------------------------------------------- >> This message was sent using IMP, the Internet Messaging Program. >> >> >> >> ------------------------------------------------------------------------------ >> This SF.net email is sponsored by >> >> Make an app they can't live without >> Enter the BlackBerry Developer Challenge >> http://p.sf.net/sfu/RIM-dev2dev >> _______________________________________________ >> Geotools-gt2-users mailing list >> Geotools-gt2-users@... >> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users >> > ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. ```
 Re: [Geotools-gt2-users] affine transformation From: Jody Garnett - 2010-09-15 07:06:03 ```If you are game more documentation is always welcome; I think the best sport would be grouped with the documentation on referencing; since that is where we introduce the generic MathTransform. You don't have to write all documentation yourself; referencing wikipedia and others also works. Before writing documentation you should have some goals on what you want to communicate; perhaps in this case it is how to scale and manipulate a single Geometry (to show what affine transform does); and then mention that it is used during rendering (so you can adjust your affine transform for the entire map). http://docs.codehaus.org/display/GEOTDOC/07+Referencing Jody On 14/09/2010, at 8:14 AM, christian.mueller@... wrote: > Hi Jody, after doing my exams there is time for adding some mathematical basics about Affine Transforms to the WIKI. > > 1) Do you still want me to add these concepts to the WIKI ? > 2) Where would be the best place ? > > Cheers > Christian > > Quoting Jody Garnett : > >> You may wish to add some of that to the wiki page :-) >> >> I will note if you don't like math, you can just use the methods of >> the AffineTransform object. >> >> Jody >> >> >> On Thu, Aug 19, 2010 at 1:01 PM, wrote: >>> >>> Some mathematical basics here. >>> An affine transform is a powerful mechanism to transform coordinates. >>> To get the new coordinates x' and y', the following calculation is done. >>> >>> [ x'] [ m00 m01 m02 ] [ x ] [ m00x + m01y + m02 ] >>> [ y'] = [ m10 m11 m12 ] [ y ] = [ m10x + m11y + m12 ] >>> [ 1 ] [ 0 0 1 ] [ 1 ] [ 1 ] >>> >>> A simple example: >>> if you want to shift a point 5 units on the x axis and -7 units at the >>> y axis, the following matrix is needed >>> >>> [ 1 0 5 ] >>> [ 0 1 -7 ] >>> [ 0 0 1 ] >>> >>> Of course, you can say this is easy, x'=x+5 and y'=y-7 would do the same. >>> >>> Another one, lets do some scaling, say factor 3 >>> >>> [ 3 0 0 ] >>> [ 0 3 0 ] >>> [ 0 0 1 ] >>> >>> This is easy too, x'=x*3 and y'=y*3 would the job. >>> >>> The power of affine transforms is that you can combine multiple >>> matrices into a single one, doing a set of individual transformations >>> within one step. There is a java method "concatenate(AffineTransform)" >>> for the AffineTransform class. But be careful, given 3 transformatons >>> A,B,C and you want to combine them in this order, you have to go from >>> right to left. >>> C concatenate B concatenate A will give you the expected result. >>> >>> A mapping from world coordinates to pixel coordinates needs some >>> operations but can be done within one affine transformation. >>> >>> The second powerful feature is that you can create an inverse >>> transform (Method createInverse), which will do the mapping in the >>> other direction out of the box. >>> >>> Believe me, if you are used to use AffineTransform objects, you will >>> use them forever. >>> >>> Hope this helps >>> Cheers >>> Christian >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> Quoting andrea antonello : >>> >>>> Hi Tommaso, >>>> the easiest way to do a rotation for example is: >>>> >>>> Coordinate ancorPoint = ...; >>>> AffineTransform affineTransform = >>>> AffineTransform.getRotateInstance(angleRad, ancorPoint.x, >>>> ancorPoint.y); >>>> MathTransform mathTransform = new AffineTransform2D(affineTransform); >>>> >>>> Point point = ...point to rotate; >>>> Geometry rotatedPoint = JTS.transform(point, mathTransform); >>>> >>>> Where point can be any geometry. >>>> >>>> Does that help? >>>> >>>> Ciao >>>> Andrea >>>> >>>> >>>> On Wed, Aug 18, 2010 at 11:26 PM, tommaso wrote: >>>>> Hallo List, >>>>> >>>>> I would like to perform some geometry transformations on polygons, i.e >>>>> rotate about a point, scale and translate. >>>>> >>>>> So I create the polygon: >>>>> >>>>> import com.vividsolutions.jts.geom.Coordinate >>>>> import org.geotools.geometry.jts.JTSFactoryFinder >>>>> import com.vividsolutions.jts.geom.GeometryFactory >>>>> import com.vividsolutions.jts.geom.LinearRing >>>>> import com.vividsolutions.jts.geom.Polygon >>>>> >>>>> GeometryFactory geometryFactory = >>>>> JTSFactoryFinder.getGeometryFactory( null ); >>>>> >>>>> Coordinate[] coords = [new Coordinate(0, 0), new Coordinate(2, 0), >>>>> new Coordinate(2, 2), new Coordinate(0, 2), new Coordinate(0, 0)] >>>>> LinearRing ring = new LinearRing(coords, geometryFactory) >>>>> Polygon polygon = geometryFactory.createPolygon(ring) >>>>> >>>>> I guess I have to use AffineTransform >>>>> (com.vividsolutions.jts.geom.util.AffineTransformation ?) but I don't know >>>>> exactly how. >>>>> A code example or a link to a tutorial were very appreciated. >>>>> >>>>> Cheers, >>>>> Tom >>>>> ------------------------------------------------------------------------------ >>>>> This SF.net email is sponsored by >>>>> >>>>> Make an app they can't live without >>>>> Enter the BlackBerry Developer Challenge >>>>> http://p.sf.net/sfu/RIM-dev2dev >>>>> _______________________________________________ >>>>> Geotools-gt2-users mailing list >>>>> Geotools-gt2-users@... >>>>> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users >>>>> >>>>> >>>> >>>> ------------------------------------------------------------------------------ >>>> This SF.net email is sponsored by >>>> >>>> Make an app they can't live without >>>> Enter the BlackBerry Developer Challenge >>>> http://p.sf.net/sfu/RIM-dev2dev >>>> _______________________________________________ >>>> Geotools-gt2-users mailing list >>>> Geotools-gt2-users@... >>>> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users >>>> >>> >>> >>> >>> ---------------------------------------------------------------- >>> This message was sent using IMP, the Internet Messaging Program. >>> >>> >>> >>> ------------------------------------------------------------------------------ >>> This SF.net email is sponsored by >>> >>> Make an app they can't live without >>> Enter the BlackBerry Developer Challenge >>> http://p.sf.net/sfu/RIM-dev2dev >>> _______________________________________________ >>> Geotools-gt2-users mailing list >>> Geotools-gt2-users@... >>> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users >>> >> > > > > ---------------------------------------------------------------- > This message was sent using IMP, the Internet Messaging Program. > > ```
 Re: [Geotools-gt2-users] affine transformation From: - 2010-09-15 07:33:02 ```I thought about an example for transforming world coords to pixel coords and the other way around. There are 3 operations involved, mirroring the y coordinate, shifting to 0.0 and scaling. Additionally it is a good use case for showing the benefits of the inversion of a matrix. Is a nice example. What do you think ? Quoting Jody Garnett : > If you are game more documentation is always welcome; I think the > best sport would be grouped with the documentation on referencing; > since that is where we introduce the generic MathTransform. > You don't have to write all documentation yourself; referencing > wikipedia and others also works. > > Before writing documentation you should have some goals on what you > want to communicate; perhaps in this case it is how to scale and > manipulate a single Geometry (to show what affine transform does); > and then mention that it is used during rendering (so you can adjust > your affine transform for the entire map). > > http://docs.codehaus.org/display/GEOTDOC/07+Referencing > > Jody > > On 14/09/2010, at 8:14 AM, christian.mueller@... wrote: > >> Hi Jody, after doing my exams there is time for adding some >> mathematical basics about Affine Transforms to the WIKI. >> >> 1) Do you still want me to add these concepts to the WIKI ? >> 2) Where would be the best place ? >> >> Cheers >> Christian >> >> Quoting Jody Garnett : >> >>> You may wish to add some of that to the wiki page :-) >>> >>> I will note if you don't like math, you can just use the methods of >>> the AffineTransform object. >>> >>> Jody >>> >>> >>> On Thu, Aug 19, 2010 at 1:01 PM, wrote: >>>> >>>> Some mathematical basics here. >>>> An affine transform is a powerful mechanism to transform coordinates. >>>> To get the new coordinates x' and y', the following calculation is done. >>>> >>>> [ x'] [ m00 m01 m02 ] [ x ] [ m00x + m01y + m02 ] >>>> [ y'] = [ m10 m11 m12 ] [ y ] = [ m10x + m11y + m12 ] >>>> [ 1 ] [ 0 0 1 ] [ 1 ] [ 1 ] >>>> >>>> A simple example: >>>> if you want to shift a point 5 units on the x axis and -7 units at the >>>> y axis, the following matrix is needed >>>> >>>> [ 1 0 5 ] >>>> [ 0 1 -7 ] >>>> [ 0 0 1 ] >>>> >>>> Of course, you can say this is easy, x'=x+5 and y'=y-7 would do the same. >>>> >>>> Another one, lets do some scaling, say factor 3 >>>> >>>> [ 3 0 0 ] >>>> [ 0 3 0 ] >>>> [ 0 0 1 ] >>>> >>>> This is easy too, x'=x*3 and y'=y*3 would the job. >>>> >>>> The power of affine transforms is that you can combine multiple >>>> matrices into a single one, doing a set of individual transformations >>>> within one step. There is a java method "concatenate(AffineTransform)" >>>> for the AffineTransform class. But be careful, given 3 transformatons >>>> A,B,C and you want to combine them in this order, you have to go from >>>> right to left. >>>> C concatenate B concatenate A will give you the expected result. >>>> >>>> A mapping from world coordinates to pixel coordinates needs some >>>> operations but can be done within one affine transformation. >>>> >>>> The second powerful feature is that you can create an inverse >>>> transform (Method createInverse), which will do the mapping in the >>>> other direction out of the box. >>>> >>>> Believe me, if you are used to use AffineTransform objects, you will >>>> use them forever. >>>> >>>> Hope this helps >>>> Cheers >>>> Christian >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> Quoting andrea antonello : >>>> >>>>> Hi Tommaso, >>>>> the easiest way to do a rotation for example is: >>>>> >>>>> Coordinate ancorPoint = ...; >>>>> AffineTransform affineTransform = >>>>> AffineTransform.getRotateInstance(angleRad, ancorPoint.x, >>>>> ancorPoint.y); >>>>> MathTransform mathTransform = new AffineTransform2D(affineTransform); >>>>> >>>>> Point point = ...point to rotate; >>>>> Geometry rotatedPoint = JTS.transform(point, mathTransform); >>>>> >>>>> Where point can be any geometry. >>>>> >>>>> Does that help? >>>>> >>>>> Ciao >>>>> Andrea >>>>> >>>>> >>>>> On Wed, Aug 18, 2010 at 11:26 PM, tommaso >>>>> wrote: >>>>>> Hallo List, >>>>>> >>>>>> I would like to perform some geometry transformations on polygons, i.e >>>>>> rotate about a point, scale and translate. >>>>>> >>>>>> So I create the polygon: >>>>>> >>>>>> import com.vividsolutions.jts.geom.Coordinate >>>>>> import org.geotools.geometry.jts.JTSFactoryFinder >>>>>> import com.vividsolutions.jts.geom.GeometryFactory >>>>>> import com.vividsolutions.jts.geom.LinearRing >>>>>> import com.vividsolutions.jts.geom.Polygon >>>>>> >>>>>> GeometryFactory geometryFactory = >>>>>> JTSFactoryFinder.getGeometryFactory( null ); >>>>>> >>>>>> Coordinate[] coords = [new Coordinate(0, 0), new >>>>>> Coordinate(2, 0), >>>>>> new Coordinate(2, 2), new Coordinate(0, 2), new Coordinate(0, 0)] >>>>>> LinearRing ring = new LinearRing(coords, geometryFactory) >>>>>> Polygon polygon = geometryFactory.createPolygon(ring) >>>>>> >>>>>> I guess I have to use AffineTransform >>>>>> (com.vividsolutions.jts.geom.util.AffineTransformation ?) but I >>>>>> don't know >>>>>> exactly how. >>>>>> A code example or a link to a tutorial were very appreciated. >>>>>> >>>>>> Cheers, >>>>>> Tom >>>>>> ------------------------------------------------------------------------------ >>>>>> This SF.net email is sponsored by >>>>>> >>>>>> Make an app they can't live without >>>>>> Enter the BlackBerry Developer Challenge >>>>>> http://p.sf.net/sfu/RIM-dev2dev >>>>>> _______________________________________________ >>>>>> Geotools-gt2-users mailing list >>>>>> Geotools-gt2-users@... >>>>>> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users >>>>>> >>>>>> >>>>> >>>>> ------------------------------------------------------------------------------ >>>>> This SF.net email is sponsored by >>>>> >>>>> Make an app they can't live without >>>>> Enter the BlackBerry Developer Challenge >>>>> http://p.sf.net/sfu/RIM-dev2dev >>>>> _______________________________________________ >>>>> Geotools-gt2-users mailing list >>>>> Geotools-gt2-users@... >>>>> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users >>>>> >>>> >>>> >>>> >>>> ---------------------------------------------------------------- >>>> This message was sent using IMP, the Internet Messaging Program. >>>> >>>> >>>> >>>> ------------------------------------------------------------------------------ >>>> This SF.net email is sponsored by >>>> >>>> Make an app they can't live without >>>> Enter the BlackBerry Developer Challenge >>>> http://p.sf.net/sfu/RIM-dev2dev >>>> _______________________________________________ >>>> Geotools-gt2-users mailing list >>>> Geotools-gt2-users@... >>>> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users >>>> >>> >> >> >> >> ---------------------------------------------------------------- >> This message was sent using IMP, the Internet Messaging Program. >> >> > > ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. ```
 Re: [Geotools-gt2-users] affine transformation From: Jody Garnett - 2010-09-22 13:26:11 ```That sounds fine; and can be used to explain to people how to transform a mouse click on the screen; to a world coordinate etc... Jody On 15/09/2010, at 5:32 PM, christian.mueller@... wrote: > I thought about an example for transforming world coords to pixel coords and the other way around. > There are 3 operations involved, mirroring the y coordinate, shifting to 0.0 and scaling. Additionally it is a good use case for showing the benefits of the inversion of a matrix. > > Is a nice example. What do you think ? > > Quoting Jody Garnett : > >> If you are game more documentation is always welcome; I think the best sport would be grouped with the documentation on referencing; since that is where we introduce the generic MathTransform. >> You don't have to write all documentation yourself; referencing wikipedia and others also works. >> >> Before writing documentation you should have some goals on what you want to communicate; perhaps in this case it is how to scale and manipulate a single Geometry (to show what affine transform does); and then mention that it is used during rendering (so you can adjust your affine transform for the entire map). >> >> http://docs.codehaus.org/display/GEOTDOC/07+Referencing >> >> Jody >> >> On 14/09/2010, at 8:14 AM, christian.mueller@... wrote: >> >>> Hi Jody, after doing my exams there is time for adding some mathematical basics about Affine Transforms to the WIKI. >>> >>> 1) Do you still want me to add these concepts to the WIKI ? >>> 2) Where would be the best place ? >>> >>> Cheers >>> Christian >>> >>> Quoting Jody Garnett : >>> >>>> You may wish to add some of that to the wiki page :-) >>>> >>>> I will note if you don't like math, you can just use the methods of >>>> the AffineTransform object. >>>> >>>> Jody >>>> >>>> >>>> On Thu, Aug 19, 2010 at 1:01 PM, wrote: >>>>> >>>>> Some mathematical basics here. >>>>> An affine transform is a powerful mechanism to transform coordinates. >>>>> To get the new coordinates x' and y', the following calculation is done. >>>>> >>>>> [ x'] [ m00 m01 m02 ] [ x ] [ m00x + m01y + m02 ] >>>>> [ y'] = [ m10 m11 m12 ] [ y ] = [ m10x + m11y + m12 ] >>>>> [ 1 ] [ 0 0 1 ] [ 1 ] [ 1 ] >>>>> >>>>> A simple example: >>>>> if you want to shift a point 5 units on the x axis and -7 units at the >>>>> y axis, the following matrix is needed >>>>> >>>>> [ 1 0 5 ] >>>>> [ 0 1 -7 ] >>>>> [ 0 0 1 ] >>>>> >>>>> Of course, you can say this is easy, x'=x+5 and y'=y-7 would do the same. >>>>> >>>>> Another one, lets do some scaling, say factor 3 >>>>> >>>>> [ 3 0 0 ] >>>>> [ 0 3 0 ] >>>>> [ 0 0 1 ] >>>>> >>>>> This is easy too, x'=x*3 and y'=y*3 would the job. >>>>> >>>>> The power of affine transforms is that you can combine multiple >>>>> matrices into a single one, doing a set of individual transformations >>>>> within one step. There is a java method "concatenate(AffineTransform)" >>>>> for the AffineTransform class. But be careful, given 3 transformatons >>>>> A,B,C and you want to combine them in this order, you have to go from >>>>> right to left. >>>>> C concatenate B concatenate A will give you the expected result. >>>>> >>>>> A mapping from world coordinates to pixel coordinates needs some >>>>> operations but can be done within one affine transformation. >>>>> >>>>> The second powerful feature is that you can create an inverse >>>>> transform (Method createInverse), which will do the mapping in the >>>>> other direction out of the box. >>>>> >>>>> Believe me, if you are used to use AffineTransform objects, you will >>>>> use them forever. >>>>> >>>>> Hope this helps >>>>> Cheers >>>>> Christian >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> Quoting andrea antonello : >>>>> >>>>>> Hi Tommaso, >>>>>> the easiest way to do a rotation for example is: >>>>>> >>>>>> Coordinate ancorPoint = ...; >>>>>> AffineTransform affineTransform = >>>>>> AffineTransform.getRotateInstance(angleRad, ancorPoint.x, >>>>>> ancorPoint.y); >>>>>> MathTransform mathTransform = new AffineTransform2D(affineTransform); >>>>>> >>>>>> Point point = ...point to rotate; >>>>>> Geometry rotatedPoint = JTS.transform(point, mathTransform); >>>>>> >>>>>> Where point can be any geometry. >>>>>> >>>>>> Does that help? >>>>>> >>>>>> Ciao >>>>>> Andrea >>>>>> >>>>>> >>>>>> On Wed, Aug 18, 2010 at 11:26 PM, tommaso wrote: >>>>>>> Hallo List, >>>>>>> >>>>>>> I would like to perform some geometry transformations on polygons, i.e >>>>>>> rotate about a point, scale and translate. >>>>>>> >>>>>>> So I create the polygon: >>>>>>> >>>>>>> import com.vividsolutions.jts.geom.Coordinate >>>>>>> import org.geotools.geometry.jts.JTSFactoryFinder >>>>>>> import com.vividsolutions.jts.geom.GeometryFactory >>>>>>> import com.vividsolutions.jts.geom.LinearRing >>>>>>> import com.vividsolutions.jts.geom.Polygon >>>>>>> >>>>>>> GeometryFactory geometryFactory = >>>>>>> JTSFactoryFinder.getGeometryFactory( null ); >>>>>>> >>>>>>> Coordinate[] coords = [new Coordinate(0, 0), new Coordinate(2, 0), >>>>>>> new Coordinate(2, 2), new Coordinate(0, 2), new Coordinate(0, 0)] >>>>>>> LinearRing ring = new LinearRing(coords, geometryFactory) >>>>>>> Polygon polygon = geometryFactory.createPolygon(ring) >>>>>>> >>>>>>> I guess I have to use AffineTransform >>>>>>> (com.vividsolutions.jts.geom.util.AffineTransformation ?) but I don't know >>>>>>> exactly how. >>>>>>> A code example or a link to a tutorial were very appreciated. >>>>>>> >>>>>>> Cheers, >>>>>>> Tom >>>>>>> ------------------------------------------------------------------------------ >>>>>>> This SF.net email is sponsored by >>>>>>> >>>>>>> Make an app they can't live without >>>>>>> Enter the BlackBerry Developer Challenge >>>>>>> http://p.sf.net/sfu/RIM-dev2dev >>>>>>> _______________________________________________ >>>>>>> Geotools-gt2-users mailing list >>>>>>> Geotools-gt2-users@... >>>>>>> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users >>>>>>> >>>>>>> >>>>>> >>>>>> ------------------------------------------------------------------------------ >>>>>> This SF.net email is sponsored by >>>>>> >>>>>> Make an app they can't live without >>>>>> Enter the BlackBerry Developer Challenge >>>>>> http://p.sf.net/sfu/RIM-dev2dev >>>>>> _______________________________________________ >>>>>> Geotools-gt2-users mailing list >>>>>> Geotools-gt2-users@... >>>>>> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users >>>>>> >>>>> >>>>> >>>>> >>>>> ---------------------------------------------------------------- >>>>> This message was sent using IMP, the Internet Messaging Program. >>>>> >>>>> >>>>> >>>>> ------------------------------------------------------------------------------ >>>>> This SF.net email is sponsored by >>>>> >>>>> Make an app they can't live without >>>>> Enter the BlackBerry Developer Challenge >>>>> http://p.sf.net/sfu/RIM-dev2dev >>>>> _______________________________________________ >>>>> Geotools-gt2-users mailing list >>>>> Geotools-gt2-users@... >>>>> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users >>>>> >>>> >>> >>> >>> >>> ---------------------------------------------------------------- >>> This message was sent using IMP, the Internet Messaging Program. >>> >>> >> >> > > > > ---------------------------------------------------------------- > This message was sent using IMP, the Internet Messaging Program. > > ```