ThinkGeo.com    |     Documentation    |     Premium Support

Bulk transform of many features

Good morning,

I was wondering if you have any built in tools for doing bulk transformations on larger collections of features, for example moving, rotating and resizing. Not thinking so much about the UI at the moment but some sort of method call like:

var transfromedFeatures = Transform(features, transformationInformation)

Thanks,
Jonathan

Ho Jonathan,

We don’t have bulk transformation but you can do it one by one, here below is how to transform an areaShape for example:

        var shape = feature.GetShape();  // convert the feature to a shape

        if (shape is AreaBaseShape areaShape) // cast it to areaShape in this demo code, you cannot Scale a PointShape
        {
            areaShape.TranslateByOffset(xOffsetDistance, yOffsetDistance);
            areaShape.ScaleTo(scale); 
            areaShape.Rotate(pivotPoint, degrees);
        }

Thanks,
Ben

Hi Ben,

Thanks, that is useful but not sure I can quite get to where I want to that way.

  1. TranslateByOffest should work fine in an iteration over many shapes
  2. ScaleTo I do not think would work as each feature would scale in place rather than to a common origin
  3. Rotate should be fine as we could can use the same pivot point for all features so they all rotate around the same origin. I can see why points might appear not to need a rotation, but I think they would so that they can be rotated as a sort of constellation.

I think using NetTopologySuite might be the way to go?

Thanks,
Jonathan

Hi Jonathan,

Another thing you can do is to add multiple shape to one GeometryCollectionShape and then do the transformation. Something like following. Have a try see if that meets your requirement.

  var shape = feature.GetShape();
  GeometryCollectionShape geometryCollectionShape = new GeometryCollectionShape();
  geometryCollectionShape.Shapes.Add(shape);

  geometryCollectionShape.Rotate(pivotPoint, degrees);
  geometryCollectionShape.TranslateByOffset(xOffsetDistance, yOffsetDistance);
  geometryCollectionShape.ScaleTo(scale);

I

I meant it doesn’t make much sense to scale a point, instead of rotating a point.
Yes, you can use NTS as well. You can get the WKB from a feature by using feature.GetWellKnownBinary(), with that you can initialize an NTS Geometry.

Thanks,
Ben

Hi Ben, thanks I will give that a try.
Jonathan

Sure, just let us know if you see any issues.

Hi Ben, thanks, will do. I have tried out using NetTopologySuite directly and it worked well, soI just need to work out a strategy for managing features columns and so on as need to make sure that all works correctly.
Regards, Jonathan

We are using NTS behind the scenes in ThinkGeo as well. You can for sure use it directly. :+1: