The background to my problem is that I have a bunch of geometries (huge amount, think map over a larger area) split across multiple wpf geometry instances (originally they were PathGeometry, but to reduce memory usage I pre-process them and create StreamGeometries during load). Now what I want to do is to generate tiles from these geometries.
Basically I would like to take a larger geometry object and "cut out" a rectangle of it (my tile) so I get several smaller geometries. Something like the image below:
Notice that I want the result to be a new geometry, not a rendering. I know I can achieve the visual result by applying a clip to a UIElement or by pushing a clip to a drawingvisual.
I've tried using Geometry.Combine with one of the arguments being the clip rectangle, but I can't get it to do what I want (I typically only get the clip rect back, or an empty geometry, depending on which combine mode I use).
Alternatively, if this cannot be done using WPF, is there any other (third party is ok) general purporse geometry API for .NET that can do these kind of operations? Or maybe this can be implemented using other parts of the WPF geometry API?
Code shows the bottom right rectangle like in your "smaller tiles" visualisation:
var geometry = MyOriginalPath.Data.Clone();
var bounds = geometry.Bounds;
var rectangleGeometry = new RectangleGeometry(bounds);
var halfWidth = bounds.Width * 0.5;
var halfHeight = bounds.Height * 0.5;
var bottomQuarter = new RectangleGeometry(
new Rect(bounds.X + halfWidth, bounds.Y + halfHeight,
halfWidth, halfHeight));
var combinedGeometry = new CombinedGeometry(GeometryCombineMode.Exclude,
rectangleGeometry, bottomQuarter);
combinedGeometry = new CombinedGeometry(GeometryCombineMode.Exclude,
geometry, combinedGeometry);
MyBottomQuarterPath.Data = combinedGeometry;
Regards Dave
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With