Class PreparedGeometryFactory

 1 /*
 2  * Copyright (c) 2016 Vivid Solutions.
 3  *
 4  * All rights reserved. This program and the accompanying materials
 5  * are made available under the terms of the Eclipse Public License 2.0
 6  * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
 7  * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v20.html
 8  * and the Eclipse Distribution License is available at
 9  *
10  * http://www.eclipse.org/org/documents/edl-v10.php.
11  */
12 package org.locationtech.jts.geom.prep;
13  
14 import org.locationtech.jts.geom.Geometry;
15 import org.locationtech.jts.geom.Lineal;
16 import org.locationtech.jts.geom.Polygonal;
17 import org.locationtech.jts.geom.Puntal;
18  
19 /**
20  * A factory for creating {@link PreparedGeometry}s.
21  * It chooses an appropriate implementation of PreparedGeometry
22  * based on the geometric type of the input geometry.
23  * <p>
24  * In the future, the factory may accept hints that indicate
25  * special optimizations which can be performed.
26  * <p>
27  * Instances of this class are thread-safe. 
28  * 
29  * @author Martin Davis
30  *
31  */
32 public class PreparedGeometryFactory 
33 {
34   /**
35    * Creates a new {@link PreparedGeometry} appropriate for the argument {@link Geometry}.
36    * 
37    * @param geom the geometry to prepare
38    * @return the prepared geometry
39    */
40     public static PreparedGeometry prepare(Geometry geom)
41     {
42         return (new PreparedGeometryFactory()).create(geom); 
43     }
44  
45   public PreparedGeometryFactory() {
46   }
47  
48   /**
49    * Creates a new {@link PreparedGeometry} appropriate for the argument {@link Geometry}.
50    * 
51    * @param geom the geometry to prepare
52    * @return the prepared geometry
53    */
54   public PreparedGeometry create(Geometry geom)
55   {
56     if (geom instanceof Polygonal) 
57       return new PreparedPolygon((Polygonal) geom);
58     if (geom instanceof Lineal) 
59       return new PreparedLineString((Lineal) geom);
60     if (geom instanceof Puntal) 
61       return new PreparedPoint((Puntal) geom);
62     
63     /**
64      * Default representation.
65      */
66     return new BasicPreparedGeometry(geom);
67   }
68 }
69