Re: [Jts-topo-suite-user] how to best store geometries for fast access
Brought to you by:
dr_jts
From: andrea a. <and...@gm...> - 2011-09-23 09:31:40
|
And when Mr. Katz Award speaks up, how can't I run? :) First, I also wanted to congratulate you for the award. Second, I owe a serialization testcase, which could be the following? It serializes geometries into tree objects (to add some more to it), then serializes the QuadTree. And then the same the way round, testing a query that extracts two geometries. Would that be ok? /** * Test {@link Quadtree} serialization. */ public class TestJtsQuadtreeSerialization extends HMTestCase { public void testJtsQuadtreeSerialization() throws Exception { WKTReader r = new WKTReader(); Geometry polygon = r.read("POLYGON ((210 350, 230 310, 290 350, 290 350, 210 350))"); polygon.setUserData(new Integer(1)); Geometry line = r.read("LINESTRING (50 380, 90 210, 180 160, 240 40, 240 40)"); line.setUserData(new Integer(2)); Geometry point = r.read("POINT (130 120)"); point.setUserData(new Integer(3)); Geometry[] geoms = {point, line, polygon}; // put geometries serialized in quadtree Quadtree tree = new Quadtree(); for( int i = 0; i < geoms.length; i++ ) { Geometry geometry = geoms[i]; byte[] geomBytes = serialize(geometry); Envelope envelope = geometry.getEnvelopeInternal(); tree.insert(envelope, geomBytes); } // serialize tree byte[] serializedTree = serialize(tree); // deserialize tree ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(serializedTree)); Quadtree deserializedTree = (Quadtree) in.readObject(); // query the polygon envelope and extract the geometries Envelope polEnvelope = polygon.getEnvelopeInternal(); List geomList = deserializedTree.query(polEnvelope); assertTrue(geomList.size() == 2); byte[] polygonGeomObj = (byte[]) geomList.get(0); in = new ObjectInputStream(new ByteArrayInputStream(polygonGeomObj)); Geometry geometry = (Geometry) in.readObject(); Integer userData = (Integer) geometry.getUserData(); if (userData == 2) { assertEquals("LineString", geometry.getGeometryType()); } if (userData == 1) { assertEquals("Polygon", geometry.getGeometryType()); } } private static byte[] serialize( Object obj ) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(bos); out.writeObject(obj); out.close(); byte[] treeBytes = bos.toByteArray(); return treeBytes; } } Hope this helps, Ciao Andrea On Wed, Sep 21, 2011 at 10:31 PM, Martin Davis <mtn...@gm...> wrote: > Hmm... nothing firm, it depends on how I organize a lot of competing > demands on time! But this shouldn't take too much time to do, especially > with Andrea's experiment. Hopefully within a week or so... > Actually the hardest part is coming up with a unit test to ensure that the > Serialization works. If someone can contribute such a test that would be > great. Otherwise the work might get down sooner than the QA... 8^) > > On Wed, Sep 21, 2011 at 1:26 PM, Mark Coletti <mco...@gm...> wrote: >> >> On Wed, Sep 7, 2011 at 10:46 AM, Martin Davis <mtn...@te...> wrote: >> > No, the indexes can certainly be made Serializable. This actually came >> > up already a while ago on this list - it's on my to-do list. >> > >> > If you get a chance to figure out what classes need to be made >> > Serializable, that would help. >> >> Glad to see that serialization is on the to do list! :D Do you have >> a guesstimate of when this will happen? >> >> Cheers! >> >> Mark Coletti >> mco...@gm... >> >> >> ------------------------------------------------------------------------------ >> All the data continuously generated in your IT infrastructure contains a >> definitive record of customers, application performance, security >> threats, fraudulent activity and more. Splunk takes this data and makes >> sense of it. Business sense. IT sense. Common sense. >> http://p.sf.net/sfu/splunk-d2dcopy1 >> _______________________________________________ >> Jts-topo-suite-user mailing list >> Jts...@li... >> https://lists.sourceforge.net/lists/listinfo/jts-topo-suite-user > > > ------------------------------------------------------------------------------ > All the data continuously generated in your IT infrastructure contains a > definitive record of customers, application performance, security > threats, fraudulent activity and more. Splunk takes this data and makes > sense of it. Business sense. IT sense. Common sense. > http://p.sf.net/sfu/splunk-d2dcopy1 > _______________________________________________ > Jts-topo-suite-user mailing list > Jts...@li... > https://lists.sourceforge.net/lists/listinfo/jts-topo-suite-user > > |