Revision 45634 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.geometry/org.gvsig.fmap.geometry.jts/src/main/java/org/gvsig/fmap/geom/jts/DefaultGeometryManager.java
DefaultGeometryManager.java | ||
---|---|---|
30 | 30 |
import java.util.Iterator; |
31 | 31 |
import java.util.List; |
32 | 32 |
import java.util.Map; |
33 |
import org.apache.commons.codec.binary.Hex; |
|
34 |
import org.apache.commons.lang3.StringUtils; |
|
33 | 35 |
import org.cresques.cts.IProjection; |
34 |
|
|
35 |
import org.slf4j.Logger; |
|
36 |
import org.slf4j.LoggerFactory; |
|
37 |
|
|
38 | 36 |
import org.gvsig.fmap.geom.Geometry; |
39 | 37 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
40 | 38 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
... | ... | |
79 | 77 |
import org.gvsig.tools.service.Service; |
80 | 78 |
import org.gvsig.tools.service.ServiceException; |
81 | 79 |
import org.gvsig.tools.service.spi.ServiceFactory; |
82 |
import org.apache.commons.codec.binary.Hex;
|
|
83 |
import org.apache.commons.lang3.StringUtils;
|
|
80 |
import org.slf4j.Logger;
|
|
81 |
import org.slf4j.LoggerFactory;
|
|
84 | 82 |
|
85 | 83 |
/** |
86 | 84 |
* Default implementation for the {@link GeometryManager}. When the |
... | ... | |
94 | 92 |
public class DefaultGeometryManager implements GeometryManager { |
95 | 93 |
|
96 | 94 |
private static final Logger LOGGER = LoggerFactory.getLogger(GeometryManager.class); |
95 |
|
|
96 |
/** |
|
97 |
* Offset for GeometryType -1 value (UNKNOWN) |
|
98 |
*/ |
|
99 |
private final int GEOMETRY_TYPE_OFFSET = 1; |
|
100 |
|
|
97 | 101 |
private double flatness = 0.8; |
98 | 102 |
|
99 | 103 |
private final Map spatialIndexFactories = new HashMap(); |
... | ... | |
126 | 130 |
* registered. |
127 | 131 |
*/ |
128 | 132 |
private GeometryType[][] geometryTypes; |
129 |
|
|
130 |
// Initially create a matrix of 26 x 6, which are the current default
|
|
133 |
|
|
134 |
// Initially create a matrix of 27 x 6, which are the current default
|
|
131 | 135 |
// types and subtypes. If another type or subtype is registered, the |
132 | 136 |
// matrix will grow as needed |
133 |
private static final int DEFAULT_TYPES_SIZE = 26;
|
|
137 |
private static final int DEFAULT_TYPES_SIZE = 27; // [-1, 25]
|
|
134 | 138 |
private static final int DEFAULT_SUBTYPES_SIZE = 6; |
135 | 139 |
|
136 | 140 |
public DefaultGeometryManager() throws GeometryException { |
... | ... | |
313 | 317 |
throw new IllegalArgumentException(geomClass.getName() + " must implement the Geometry interface"); |
314 | 318 |
} |
315 | 319 |
|
320 |
int offsettedType = type + GEOMETRY_TYPE_OFFSET; |
|
316 | 321 |
// Check if it is registered |
317 | 322 |
GeometryType geomType = null; |
318 |
if (type >= geometryTypes.length || subType >= geometryTypes[0].length
|
|
319 |
|| (geomType = geometryTypes[type][subType]) == null) {
|
|
320 |
geomType = new DefaultGeometryType(geomClass, name, type, subType, superTypes, superSubTypes); |
|
323 |
if (offsettedType >= geometryTypes.length || subType >= geometryTypes[0].length
|
|
324 |
|| (geomType = geometryTypes[offsettedType][subType]) == null) {
|
|
325 |
geomType = new DefaultGeometryType(geomClass, name, type, subType, superTypes, superSubTypes); //Attention!
|
|
321 | 326 |
registerGeometryType(geomType); |
322 | 327 |
} |
323 | 328 |
|
... | ... | |
328 | 333 |
|
329 | 334 |
@Override |
330 | 335 |
public void registerGeometryType(GeometryType geometryType) { |
331 |
if (geometryType.getType() >= geometryTypes.length || geometryType.getSubType() >= geometryTypes[0].length) { |
|
336 |
int offsettedType = geometryType.getType() + GEOMETRY_TYPE_OFFSET; |
|
337 |
if (offsettedType >= geometryTypes.length || geometryType.getSubType() >= geometryTypes[0].length) { |
|
332 | 338 |
|
333 | 339 |
// Recreate the geometry type matrix if the types |
334 | 340 |
// or subtypes don't fit |
335 | 341 |
int newTypesSize = |
336 |
geometryType.getType() < geometryTypes.length ? geometryTypes.length : geometryType.getType() + 1;
|
|
342 |
offsettedType < geometryTypes.length ? geometryTypes.length : offsettedType + 1;
|
|
337 | 343 |
int newSubTypesSize = |
338 | 344 |
geometryType.getSubType() < geometryTypes[0].length ? geometryTypes[0].length : geometryType |
339 | 345 |
.getSubType() + 1; |
... | ... | |
345 | 351 |
geometryTypes = newMatrix; |
346 | 352 |
} |
347 | 353 |
|
348 |
geometryTypes[geometryType.getType()][geometryType.getSubType()] = geometryType;
|
|
354 |
geometryTypes[offsettedType][geometryType.getSubType()] = geometryType;
|
|
349 | 355 |
geometryTypeName.put(geometryType.getName(), geometryType); |
350 | 356 |
} |
351 | 357 |
|
... | ... | |
357 | 363 |
@Override |
358 | 364 |
public GeometryType getGeometryType(int type, int subType) throws GeometryTypeNotSupportedException, |
359 | 365 |
GeometryTypeNotValidException { |
360 |
if (type >= geometryTypes.length || subType >= geometryTypes[0].length) { |
|
366 |
|
|
367 |
int offsettedType = type + GEOMETRY_TYPE_OFFSET; |
|
368 |
|
|
369 |
if (offsettedType >= geometryTypes.length || subType >= geometryTypes[0].length) { |
|
361 | 370 |
throw new GeometryTypeNotValidException(type, subType); |
362 | 371 |
} |
363 |
GeometryType gType = geometryTypes[type][subType];
|
|
372 |
GeometryType gType = geometryTypes[offsettedType][subType];
|
|
364 | 373 |
if (gType == null) { |
365 | 374 |
throw new GeometryTypeNotSupportedException(type, subType); |
366 | 375 |
} |
Also available in: Unified diff