Geospatial Features in MongoDB with Jaspersoft
Lately I have been posting technical examples to the Jaspersoft community wiki instead of this blog. I'll cross-post this one because there are not many examples of doing this. When working with Geospatial data, I found the $near operator to be pretty sweet. Let me show you by example.
In the screenshots below you'll see that I constructed a report that shows "cases" on a map. When you click on a specific case you will be taken to a detail level report. The detail level report will show you cases nearby for that service. So for example, if someone reports a broken street light on Market Street, this might help you locate similar cases.
Line 8: The $P{location} parameter is a java.util.List that contains longitude and latitude coordinates, something like [-122.4194200,37.7749300]
Line 11: How many meters from the center (specified in line 8) should it search
Line 13: The $P{service} parameter is a string containing the name of the Service, in the screenshot above it's Missing Sign
You will need to have an index on your location field, like so: ensureIndex({"location" : "2dsphere" } )
In the screenshots below you'll see that I constructed a report that shows "cases" on a map. When you click on a specific case you will be taken to a detail level report. The detail level report will show you cases nearby for that service. So for example, if someone reports a broken street light on Market Street, this might help you locate similar cases.
So how is it done?
Quite simple really, take a look at this mongodb query:
That's it, I've never really done anything with geospatial data and this seemed like it was a piece of cake.
References:
- Download the example data and reports from the Jaspersoft Community Wiki
- Read about the MongoDB $near operator
- Watch me present on this subject
Comments