Revision 13811 trunk/libraries/libTopology/src/org/gvsig/jts/GeometryCracker.java

View differences:

GeometryCracker.java
1
/*
2
 * Created on 07-sep-2007
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
/* CVS MESSAGES:
45
 *
46
 * $Id: 
47
 * $Log:
48
 */
1 49
package org.gvsig.jts;
2 50

  
3 51
import com.vividsolutions.jts.algorithms.SnapCGAlgorithms;
4 52
import com.vividsolutions.jts.geom.Coordinate;
5 53
import com.vividsolutions.jts.geom.CoordinateList;
6 54
import com.vividsolutions.jts.geom.Geometry;
7
import com.vividsolutions.jts.geom.GeometryFactory;
8 55
import com.vividsolutions.jts.geom.LineSegment;
9
import com.vividsolutions.jts.geom.LinearRing;
10 56

  
11 57
/**
12 58
 * Cracks the geometries of a topology's layers to force the sharing of
......
24 70
 */
25 71
public class GeometryCracker {
26 72

  
27
	private static GeometryFactory geomFactory = new GeometryFactory();
28

  
29 73
	private LineSegment seg = new LineSegment();
30 74

  
31 75
	private double snapTolerance;
......
64 108
		GeometryCracker cracker = new GeometryCracker(snapTolerance);
65 109
		Coordinate[] newCoordsA = cracker.crackTo(a.getCoordinates(), b
66 110
				.getCoordinates());
67
		return createGeometry(newCoordsA, a.getGeometryType());
111
		return JtsUtil.createGeometry(newCoordsA, a.getGeometryType());
68 112
	}
69 113
	
70 114
	
71 115
	public Geometry crack(Geometry a, Geometry b){
72 116
		Coordinate[] newCoordsA = crackTo(a.getCoordinates(), b.getCoordinates());
73
		return createGeometry(newCoordsA, a.getGeometryType());
117
		return JtsUtil.createGeometry(newCoordsA, a.getGeometryType());
74 118
	}
75 119
	
76
	
77

  
78
	private static Geometry createGeometry(Coordinate[] coords,
79
			String geometryType) {
80
		if (geometryType.equalsIgnoreCase("POINT")) {
81
			return geomFactory.createPoint(coords[0]);
82
		} else if (geometryType.equalsIgnoreCase("LINESTRING")) {
83
			return geomFactory.createLineString(coords);
84
		}else if (geometryType.equalsIgnoreCase("LINEARRING")) {
85
			return geomFactory.createLinearRing(coords);
86
		}  
87
		else if (geometryType.equalsIgnoreCase("POLYGON")) {
88
			LinearRing exterior = geomFactory.createLinearRing(coords);
89
			return geomFactory.createPolygon(exterior, null);
90
		}
91
		return null;
92

  
93
	}
94

  
95 120
	/*
96 121
	 * This code is extracted from the class LineStringSnapper of JTS
97 122
	 */

Also available in: Unified diff