New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ShapeFactory and some builders #130
Conversation
This is a work-in progress but substantial progress. Tests don't pass. Please review; push back on what you don't like.
My thoughts for the road ahead:
|
Not much to add here except I really like the general direction and I think the api looks good.. Likely won't have much actual useful feedback (which I am sure would all be minor) until I actually start to use the new apis, but from what I can gleen from the diff this is looking great. |
Current coverage is
|
Ok; so far GeoJSONReader & reading WKTReader have moved over. Reading PolyshapeReader has not yet. @jdeolive may I suggest you give that a shot? Ok I just did; I'm hopeful to get some help here, and in the process getting your input. I admit that the builder for the Multi* shapes is maybe a little weird in that, say for a MultiPolygonBuilder, you call The only nocommit is related to the "norm" methods (moved to ShapeFactory) that were documented as only applying to WKTReader. Indeed only WKTReader calls them but that's only because it used to be the only reader; the intention is that all readers (other than a Binary one) should call those methods. The idea being that there may be some normalization (e.g. rounding or correcting) to be done before verifyX is called, which can throw. The simplest thing is just to keep them, but also ensure we add them to GeoJSONReader & PolyshapeReader -- it's simple enough. Figuring out when Spatial4j should normalize or verify stuff, and when it shouldn't is debatable. |
Hey @dsmiley, sorry for the late response, been on the road the last few days. I'll pull this down later today and take a shot at PolyshapeReader. |
Hey @dsmiley. Took a crack at porting PolyshapeReader. All went smooth for the most part. The only hitch is that the PolyshapeReader has an override for the JTS version that tries to build the specific types of homogeneous geometry collection if it can. You mention in your original comments perhaps adding a flag to Jts context factory to control this behaviour. +1 on that idea. I can take a crack at adding that logic, although I wouldn't be able to get to it until next week. |
Sounds good to me Justin. And I think you for forgot to add calls to the norm() methods. |
Ahh, right. Missed that. Norm() method calls added. As I went through I was wondering if that is something that could potentially be integrated into the builder classes and happen automatically? |
I know what you mean; there seems to be room for improvement. Certainly when reading from "external" data (e.g. WKT, GeoJSON, or whatever) you'd want -- it's what it was intended for... but if you're reading data that has already been normalized (some binary serialized format) or on the fly generation of rectangles (e.g. that Lucene spatial does when traversing a grid) it's unnecessary overhead. |
Hey @dsmiley , I spec'd out an initial approach for adding the logic to use JtsGeometry vs ShapeCollection to JtsShapeFactory. Here are my thoughts/findings. First was I notice that there is already a useJtsMulti flag available. I was thinking it made sense to use that. Or do you think this deserves a different flag? Second, is that ShapeFactory.multiShape(List) returns a ShapeCollection, meaning we can't return a JtsGeometry from it. From your previous comments it looks like your thinking is to make ShapeCollection an interface and adding a implementation for jts. I think that makes sense so unless you object I'll go that route. |
RE useJtsMulti: sure, we can always do this when useJtsMulti. If one day we want to sometimes not do it despite useJtsMulti being true, we can then add a separate option. RE ShapeFactory.multiShape(List): Hmmm. I'd rather try and get this feature branch done without messing with the types, and leave that for a separate issue (following the org.location.spatial4j / LocationTech official release). Perhaps we could either punt on this feature or only do it when we use the MultiShapeBuilder since it returns a Shape? |
Fair enough, happy to punt on that approach for now and go with your suggestion of just making the change in the builder only for now. Should have a patch for you to review tomorrow. |
Ok, just submitted #131 which will merge the changes we discussed into this branch. Let me know what you think. |
…ometry collection. This removes the need for custom JtsPolyshapeReader.
Using JtsSpatialContextFactory.useJtsMulti to control narrowing of collections.
I enhanced the javadocs further. If you think it's mergeable I'll do that and get on the org.locationtech package rename. |
+1 on merge. |
This moves shape construction from SpatialContext to a new ShapeFactory interface.
And it formalizes polygon construction and other shapes without requiring JTS.