Scale Geometry

2238
4
07-05-2016 07:12 AM
MichaelKnight
New Contributor II


Using the 10.2.4 SDK for Java what would be the best way to scale a geometry? For example I have a series of PolyLines and would like the user to make them smaller or larger by providing them with a simple scale tool.

Thanks,

Mike

Tags (1)
0 Kudos
4 Replies
EricBader
Occasional Contributor III

Hi Michael,

Can you explain a bit more about what these Geometries are? Are the polylines representing real-world features?

0 Kudos
MichaelKnight
New Contributor II

Hi Eric, thank you for your reply.

The geometries in question are simple polylines and polygons representing building outlines for example. Here is the code i currently have:

public static Graphic scaleGraphic(Graphic graphic, double factor)

{

  Graphic scaledGraphic = null;

  if( graphic != null )

  {

  Geometry geometry = graphic.getGeometry();

  if( geometry != null)

  {

  Geometry scaledGeometry = geometry.copy();

  Transformation2D scale = new Transformation2D(factor);

  scaledGeometry.applyTransformation(scale);

  scaledGraphic = new Graphic(scaledGeometry, null, graphic.getAttributes());

  }

  }

  return scaledGraphic;

}

0 Kudos
EricBader
Occasional Contributor III

Ah. Thanks Michael.

I guess I don't have the full context of your application, so I apologize in advance if this doesn't make sense.

If your geometry from the original graphic is in map coordinates, and it gets added to the map, it will scale on it's own, without the need to apply your own transformation logic, etc.

If the coordinates are not in the current map's spatial reference, you can use the GeometryEngine to project them before adding them to the map.

Does this make sense? Am I understanding your issue correctly?

0 Kudos
MichaelKnight
New Contributor II

Hi Eric,

The geometries are in the same spacial reference as the map. I have written similar routines for moving and rotating geometries using Transformation2D which all work fine. However when I use the above routine with say a factor of 2 (twice original size) it no longer renders the graphics on the map which makes me believe the transformation is going wrong in some way.

Looking at the code provided is that all one should need to do when scaling a polyline/polygon?

0 Kudos