Differences
This shows you the differences between two versions of the page.
regions [2013/09/23 23:10] mroriz |
regions [2017/07/21 03:08] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== JTS Topology Suite====== | ||
- | To work with spatial objects we use HelperJTS. According to [[http:// | ||
- | * Unordered List Item spatial predicates (based on the DE-9IM model) | ||
- | * overlay functions (intersection, | ||
- | * buffer | ||
- | * convex hull | ||
- | * area and distance functions topological validity checking | ||
- | |||
- | and It has the following design goals: | ||
- | |||
- | * JTS conforms to the [[http:// | ||
- | * JTS provides a complete, consistent, robust implementation of fundamental 2D spatial algorithms | ||
- | * JTS is fast enough for production use | ||
- | * JTS is written in 100% pure JavaTM | ||
- | * JTS is open source (under the [[http:// | ||
- | |||
- | However, to be viable afford even millions of checks per minute, we perform some optimizations, | ||
- | |||
- | Some summary information is available: | ||
- | |||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | |||
- | | ||
- | |||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | |||
- | To actually determine a shape based on two geometry: | ||
- | |||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | |||
- | Some of the most helpful functions are: | ||
- | |||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | |||
- | The three most difficult methods are here : | ||
- | |||
- | * equals( Object ) - Returns true if this geometry is equal to the specified geometry | ||
- | * equals( Geometry ) - checks if the geometry is the same shape | ||
- | * equalsExact( Geometry ) - Returns true if the two Geometrys are exactly equal, up to a specified distance tolerance. | ||
- | |||
- | There are some book keeping methods to help discovery how the geometry was constructed: | ||
- | |||
- | * getGeometryFactory() - Gets the factory which contains the context in which this geometry was created. | ||
- | * getPreceisionModel() | ||
- | * toText() - the WKT representation of the Geometry | ||
- | * getGeoemtryType() - factory method called (ie “point”, | ||
- | |||
- | A couple of methods are there to store your developer information: | ||
- | |||
- | * getSRID() - stores the “spatial reference id”, used as an external key when working with databases | ||
- | * getUserData() - intended to be used by developers, a best practice is to store a java.util.Map. GeoTools will occasionally use this field to store a “srsName” or full CoordianteReferenceSystem. | ||
- | |||
- | The code below is based on this two polygons. Its coordinates can be viewed in GerarPoligonoA | ||
- | |||
- | {{: | ||
- | |||
- | |||
- | The operations results of the main methods follows in the table below: | ||
- | | ^ AB ^ BA ^ | ||
- | ^ Equals | ||
- | ^ Disjoint | ||
- | ^ Intersects | ||
- | ^ Touches | ||
- | ^ Crosses | ||
- | ^ Within | ||
- | ^ Contains | ||
- | ^ Overlaps | ||
- | |||
- | |||
- | < | ||
- | import java.util.ArrayList; | ||
- | import java.util.List; | ||
- | import java.util.Random; | ||
- | |||
- | import ContextNetGeo.CtxCoordinate; | ||
- | import ContextNetGeo.Polygon; | ||
- | |||
- | public class Execute { | ||
- | |||
- | /** | ||
- | * @param args | ||
- | * @throws Exception | ||
- | */ | ||
- | |||
- | public static void main(String[] args) throws Exception { | ||
- | Polygon polygonA = GerarPoligonoA(); | ||
- | Polygon polygonB = GerarPoligonoB(); | ||
- | testeOperacoes(polygonA, | ||
- | System.out.println(" | ||
- | testeCache(false, | ||
- | polygonA = GerarPoligonoA(); | ||
- | polygonB = GerarPoligonoB(); | ||
- | System.out.println(" | ||
- | testeCache(true, | ||
- | |||
- | } | ||
- | |||
- | private static void testeCache(boolean isCached, Polygon polygonA, Polygon polygonB) throws Exception { | ||
- | long startTime = System.currentTimeMillis(); | ||
- | long iterations = 0; | ||
- | //Random rdn = new Random(); | ||
- | polygonA.setCache(isCached, | ||
- | List< | ||
- | polygonA.setCache(isCached, | ||
- | polygonB.setCache(isCached, | ||
- | while (System.currentTimeMillis() - startTime < 30000) { | ||
- | // Incrementa a quantidade de iterações feitas dentro de 5 segundos. | ||
- | iterations++; | ||
- | for (CtxCoordinate ctxCoordinate : listaPontos) { | ||
- | polygonA.isPointWithin(ctxCoordinate); | ||
- | |||
- | // Incrementa a quantidade de iterações feitas dentro de 5 segundos. | ||
- | iterations++; | ||
- | } | ||
- | } | ||
- | long finishTime = System.currentTimeMillis() - startTime; | ||
- | // Calcula a média de tempo de cada iteração. | ||
- | float media = (float) finishTime / iterations; | ||
- | |||
- | if (isCached) | ||
- | System.out.println(" | ||
- | else | ||
- | System.out.println(" | ||
- | |||
- | System.out.println(" | ||
- | } | ||
- | |||
- | private static List< | ||
- | |||
- | ArrayList< | ||
- | Random rdn = new Random(); | ||
- | for (int i = 0; i < 50; i++) { | ||
- | list.add(new CtxCoordinate(rdn.nextInt(100), | ||
- | } | ||
- | |||
- | return list; | ||
- | } | ||
- | |||
- | private static void testeOperacoes(Polygon polygonA, Polygon polygonB) { | ||
- | System.out.println(" | ||
- | System.out.println(" | ||
- | System.out.println(" | ||
- | System.out.println(" | ||
- | System.out.println(" | ||
- | System.out.println(" | ||
- | System.out.println(" | ||
- | System.out.println(" | ||
- | System.out.println(" | ||
- | |||
- | System.out.println(" | ||
- | System.out.println(" | ||
- | System.out.println(" | ||
- | System.out.println(" | ||
- | System.out.println(" | ||
- | System.out.println(" | ||
- | System.out.println(" | ||
- | System.out.println(" | ||
- | System.out.println(" | ||
- | System.out.println(" | ||
- | } | ||
- | |||
- | private static Polygon GerarPoligonoA() { | ||
- | // Poligono 1 - Externa | ||
- | ArrayList< | ||
- | |||
- | listaCoordenadasMaster.add(new CtxCoordinate(30, | ||
- | listaCoordenadasMaster.add(new CtxCoordinate(130, | ||
- | listaCoordenadasMaster.add(new CtxCoordinate(250, | ||
- | listaCoordenadasMaster.add(new CtxCoordinate(320, | ||
- | listaCoordenadasMaster.add(new CtxCoordinate(250, | ||
- | listaCoordenadasMaster.add(new CtxCoordinate(70, | ||
- | listaCoordenadasMaster.add(new CtxCoordinate(30, | ||
- | |||
- | // Poligono 1 - Interna | ||
- | ArrayList< | ||
- | listaCoordenadasEscravo.add(new CtxCoordinate(140, | ||
- | listaCoordenadasEscravo.add(new CtxCoordinate(110, | ||
- | listaCoordenadasEscravo.add(new CtxCoordinate(230, | ||
- | listaCoordenadasEscravo.add(new CtxCoordinate(140, | ||
- | listaCoordenadasEscravo.add(new CtxCoordinate(140, | ||
- | |||
- | return new Polygon(listaCoordenadasMaster, | ||
- | } | ||
- | |||
- | private static Polygon GerarPoligonoB() { | ||
- | // Poligono 1 - Externa | ||
- | ArrayList< | ||
- | listaCoordenadasMaster.add(new CtxCoordinate(210, | ||
- | listaCoordenadasMaster.add(new CtxCoordinate(180, | ||
- | listaCoordenadasMaster.add(new CtxCoordinate(170, | ||
- | listaCoordenadasMaster.add(new CtxCoordinate(190, | ||
- | listaCoordenadasMaster.add(new CtxCoordinate(360, | ||
- | listaCoordenadasMaster.add(new CtxCoordinate(470, | ||
- | listaCoordenadasMaster.add(new CtxCoordinate(440, | ||
- | listaCoordenadasMaster.add(new CtxCoordinate(210, | ||
- | |||
- | // Poligono 1 - Interna | ||
- | ArrayList< | ||
- | listaCoordenadasEscravo.add(new CtxCoordinate(340, | ||
- | listaCoordenadasEscravo.add(new CtxCoordinate(250, | ||
- | listaCoordenadasEscravo.add(new CtxCoordinate(270, | ||
- | listaCoordenadasEscravo.add(new CtxCoordinate(360, | ||
- | listaCoordenadasEscravo.add(new CtxCoordinate(390, | ||
- | listaCoordenadasEscravo.add(new CtxCoordinate(340, | ||
- | |||
- | return new Polygon(listaCoordenadasMaster, | ||
- | } | ||
- | } | ||
- | |||
- | </ |