Revision 41246 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.geometry/org.gvsig.fmap.geometry.impl/src/main/java/org/gvsig/fmap/geom/impl/DefaultGeometryManager.java
DefaultGeometryManager.java | ||
---|---|---|
24 | 24 |
|
25 | 25 |
package org.gvsig.fmap.geom.impl; |
26 | 26 |
|
27 |
import org.gvsig.fmap.geom.impl.spatialIndex.SpatialIndexFactoryJTS; |
|
27 | 28 |
import java.awt.geom.PathIterator; |
28 | 29 |
import java.util.ArrayList; |
29 | 30 |
import java.util.HashMap; |
... | ... | |
41 | 42 |
import org.gvsig.fmap.geom.GeometryLocator; |
42 | 43 |
import org.gvsig.fmap.geom.GeometryManager; |
43 | 44 |
import org.gvsig.fmap.geom.SpatialIndex; |
45 |
import org.gvsig.fmap.geom.SpatialIndexFactory; |
|
44 | 46 |
import org.gvsig.fmap.geom.aggregate.MultiCurve; |
45 | 47 |
import org.gvsig.fmap.geom.aggregate.MultiSurface; |
46 | 48 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
47 | 49 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
50 |
import org.gvsig.fmap.geom.impl.spatialIndex.SpatialIndexFactoryJSI; |
|
48 | 51 |
import org.gvsig.fmap.geom.operation.GeometryOperation; |
49 | 52 |
import org.gvsig.fmap.geom.operation.GeometryOperationContext; |
50 | 53 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
... | ... | |
64 | 67 |
import org.gvsig.fmap.geom.type.GeometryTypeNotSupportedException; |
65 | 68 |
import org.gvsig.fmap.geom.type.GeometryTypeNotValidException; |
66 | 69 |
import org.gvsig.fmap.geom.type.impl.DefaultGeometryType; |
70 |
import org.gvsig.tools.dynobject.DynObject; |
|
71 |
import org.gvsig.tools.service.Service; |
|
72 |
import org.gvsig.tools.service.ServiceException; |
|
73 |
import org.gvsig.tools.service.spi.ServiceFactory; |
|
67 | 74 |
|
68 | 75 |
/** |
69 | 76 |
* Default implementation for the {@link GeometryManager}. When the |
... | ... | |
79 | 86 |
.getLogger(GeometryManager.class); |
80 | 87 |
private double flatness = 0.8; |
81 | 88 |
|
89 |
private Map spatialIndexFactories = new HashMap(); |
|
90 |
|
|
82 | 91 |
/** |
83 | 92 |
* This list holds the unique name of all registered geometry operations. |
84 | 93 |
* The index in which they are stored is also the operation code used to |
... | ... | |
114 | 123 |
private static final int DEFAULT_TYPES_SIZE = 17; |
115 | 124 |
private static final int DEFAULT_SUBTYPES_SIZE = 6; |
116 | 125 |
|
117 |
public DefaultGeometryManager() { |
|
126 |
public DefaultGeometryManager() throws GeometryException {
|
|
118 | 127 |
this(DEFAULT_TYPES_SIZE, DEFAULT_SUBTYPES_SIZE); |
119 | 128 |
} |
120 | 129 |
|
121 |
public DefaultGeometryManager(int initialTypesSize, int initialSubtypesSize) { |
|
130 |
public DefaultGeometryManager(int initialTypesSize, int initialSubtypesSize) throws GeometryException {
|
|
122 | 131 |
geometryTypes = new GeometryType[initialTypesSize][initialSubtypesSize]; |
132 |
this.addServiceFactory(new SpatialIndexFactoryJTS()); |
|
133 |
this.addServiceFactory(new SpatialIndexFactoryJSI()); |
|
123 | 134 |
} |
124 | 135 |
|
125 | 136 |
public int registerGeometryOperation(String geomOpName, |
... | ... | |
714 | 725 |
} |
715 | 726 |
} |
716 | 727 |
|
717 |
public SpatialIndex createDefaultMemorySpatialIndex() throws GeometryException { |
|
718 |
return new SpatialIndexJTS(); |
|
719 |
} |
|
720 |
|
|
721 | 728 |
public GeneralPathX createGeneralPath(int rule, PathIterator pathIterator) { |
722 | 729 |
if( pathIterator == null ) { |
723 | 730 |
return new DefaultGeneralPathX(rule); |
... | ... | |
741 | 748 |
public Surface createSurface(int subType) throws CreateGeometryException { |
742 | 749 |
return (Surface) create(TYPES.SURFACE, subType); |
743 | 750 |
} |
751 |
|
|
752 |
public SpatialIndex createDefaultMemorySpatialIndex() throws ServiceException { |
|
753 |
return this.createSpatialIndex(SpatialIndexFactoryJTS.NAME,null); |
|
754 |
} |
|
755 |
|
|
756 |
public SpatialIndex createSpatialIndex(String name, DynObject parameters) throws ServiceException { |
|
757 |
SpatialIndexFactory factory = this.getSpatialIndexFactory(name); |
|
758 |
if (factory == null) { |
|
759 |
throw new CantExistsService(name); |
|
760 |
} |
|
761 |
return (SpatialIndex) factory.create(parameters, this); |
|
762 |
} |
|
763 |
|
|
764 |
public SpatialIndexFactory getSpatialIndexFactory(String name) { |
|
765 |
return (SpatialIndexFactory) this.spatialIndexFactories.get(name); |
|
766 |
} |
|
767 |
|
|
768 |
public void addServiceFactory(ServiceFactory serviceFactory) { |
|
769 |
serviceFactory.initialize(); |
|
770 |
this.spatialIndexFactories.put(serviceFactory.getName(), serviceFactory); |
|
771 |
} |
|
772 |
|
|
773 |
public Service createService(DynObject serviceParameters) throws ServiceException { |
|
774 |
throw new UnsupportedOperationException("Not supported yet."); |
|
775 |
} |
|
776 |
|
|
777 |
public DynObject createServiceParameters(String serviceName) throws ServiceException { |
|
778 |
SpatialIndexFactory factory = this.getSpatialIndexFactory(serviceName); |
|
779 |
if( factory == null ) { |
|
780 |
throw new CantExistsService(serviceName); |
|
781 |
} |
|
782 |
return factory.createParameters(); |
|
783 |
} |
|
784 |
|
|
785 |
public Service getService(DynObject parameters) throws ServiceException { |
|
786 |
return this.createSpatialIndex((String) parameters.getDynValue("serviceName"), parameters); |
|
787 |
} |
|
788 |
|
|
789 |
public class CantExistsService extends ServiceException { |
|
790 |
|
|
791 |
public CantExistsService(String serviceName) { |
|
792 |
super("Can't existe service %(service).", "_Cant_existe_service_XserviceX", 100001); |
|
793 |
setValue("service",serviceName); |
|
794 |
} |
|
795 |
|
|
796 |
} |
|
744 | 797 |
} |
Also available in: Unified diff