Revision 954

View differences:

org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.86/org.gvsig.gpe.app/org.gvsig.gpe.app.mainplugin/buildNumber.properties
1
#Sat Oct 05 18:28:42 CEST 2019
2
buildNumber=2188
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.86/org.gvsig.gpe.app/org.gvsig.gpe.app.mainplugin/src/main/assembly/gvsig-plugin-package.xml
1
<!--
2

  
3
    gvSIG. Desktop Geographic Information System.
4

  
5
    Copyright (C) 2007-2013 gvSIG Association.
6

  
7
    This program is free software; you can redistribute it and/or
8
    modify it under the terms of the GNU General Public License
9
    as published by the Free Software Foundation; either version 3
10
    of the License, or (at your option) any later version.
11

  
12
    This program is distributed in the hope that it will be useful,
13
    but WITHOUT ANY WARRANTY; without even the implied warranty of
14
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
    GNU General Public License for more details.
16

  
17
    You should have received a copy of the GNU General Public License
18
    along with this program; if not, write to the Free Software
19
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
    MA  02110-1301, USA.
21

  
22
    For any additional information, do not hesitate to contact us
23
    at info AT gvsig.com, or visit our website www.gvsig.com.
24

  
25
-->
26
<assembly>
27
  <id>gvsig-plugin-package</id>
28
  <formats>
29
    <format>zip</format>
30
  </formats>
31
  <baseDirectory>${project.artifactId}</baseDirectory>
32
  <includeBaseDirectory>true</includeBaseDirectory>
33
  <files>
34
    <file>
35
      <source>target/${project.artifactId}-${project.version}.jar</source>
36
      <outputDirectory>lib</outputDirectory>
37
    </file>
38
    <file>
39
      <source>target/package.info</source>
40
    </file>
41
  </files>
42

  
43
  <fileSets>
44
    <fileSet>
45
      <directory>src/main/resources-plugin</directory>
46
      <outputDirectory>.</outputDirectory>
47
    </fileSet>
48
  </fileSets>
49

  
50
  <dependencySets>
51
    <dependencySet>
52
      <useProjectArtifact>false</useProjectArtifact>
53
      <useTransitiveDependencies>false</useTransitiveDependencies>
54
      <outputDirectory>lib</outputDirectory>
55
      <includes>
56
    	<include>org.gvsig:org.gvsig.gpe.lib.api</include>
57
    	<include>org.gvsig:org.gvsig.gpe.lib.spi</include>
58
    	<include>org.gvsig:org.gvsig.gpe.lib.impl</include>
59
        <include>org.gvsig:org.gvsig.gpe.prov.xml</include>
60
        <include>org.gvsig:org.gvsig.gpe.prov.gml</include>
61
        <include>org.gvsig:org.gvsig.gpe.prov.kml</include>
62
        <include>org.gvsig:org.gvsig.xmlpull.lib.api</include>
63
        <include>org.gvsig:org.gvsig.xmlpull.lib.spi</include>
64
        <include>org.gvsig:org.gvsig.xmlpull.lib.impl</include>
65
        <include>org.gvsig:org.gvsig.xmlpull.prov.stax</include>
66
        <include>org.gvsig:org.gvsig.xmlpull.prov.kxml</include>
67
        <include>org.gvsig:org.gvsig.xmlschema.lib.api</include>
68
        <include>org.gvsig:org.gvsig.xmlschema.lib.spi</include>
69
        <include>org.gvsig:org.gvsig.xmlschema.lib.impl</include>
70
        <include>org.gvsig:org.gvsig.xmlschema.prov.kxml</include>
71
        <include>stax:stax</include>
72
      </includes>
73
    </dependencySet>
74
  </dependencySets>
75

  
76
</assembly>
77

  
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.86/org.gvsig.gpe.app/org.gvsig.gpe.app.mainplugin/src/main/java/org/gvsig/gpe/GPELibraryExtension.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 {Iver T.I.}   {Task}
26
*/
27
 
28
package org.gvsig.gpe;
29

  
30
import org.gvsig.andami.IconThemeHelper;
31
import org.gvsig.andami.plugins.Extension;
32
import org.gvsig.fmap.dal.store.gpe.GPEStoreProvider;
33
import org.gvsig.fmap.mapcontext.MapContextLocator;
34

  
35

  
36
/**
37
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
38
 */
39
public class GPELibraryExtension extends Extension{
40
		
41
	public void execute(String actionCommand) {
42
	}
43

  
44
	public void initialize() {
45
		IconThemeHelper.registerIcon("layer", "layer-icon-gpe", this);
46
	}	
47

  
48
	public void postInitialize() {
49
		MapContextLocator.getMapContextManager().registerIconLayer(GPEStoreProvider.NAME, "layer-icon-gpe");
50
	}
51

  
52
	public boolean isEnabled() {
53
		return false;
54
	}
55

  
56
	public boolean isVisible() {
57
		return false;
58
	}
59

  
60
}
61

  
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.86/org.gvsig.gpe.app/org.gvsig.gpe.app.mainplugin/src/main/java/org/gvsig/fmap/dal/store/gpe/GPEStoreParameters.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2009 {Iver T.I.}   {Task}
26
 */
27

  
28
package org.gvsig.fmap.dal.store.gpe;
29

  
30
import java.io.File;
31
import org.apache.commons.lang3.BooleanUtils;
32

  
33
import org.cresques.cts.IProjection;
34
import org.gvsig.fmap.crs.CRSFactory;
35
import org.gvsig.fmap.dal.DataStore;
36
import org.gvsig.fmap.dal.DataStoreParameters;
37
import org.gvsig.fmap.dal.FileHelper;
38
import org.gvsig.fmap.dal.feature.EditableFeatureType;
39
import org.gvsig.fmap.dal.feature.FeatureType;
40
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters;
41
import org.gvsig.fmap.dal.feature.OpenFeatureStoreParameters;
42
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters;
43
import org.gvsig.fmap.dal.spi.AbstractDataParameters;
44
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
45
import org.gvsig.fmap.geom.primitive.Envelope;
46
import org.gvsig.gpe.lib.api.GPELocator;
47
import org.gvsig.gpe.lib.api.GPEManager;
48
import org.gvsig.gpe.lib.api.exceptions.ParserCreationException;
49
import org.gvsig.tools.ToolsLocator;
50
import org.gvsig.tools.dataTypes.CoercionException;
51
import org.gvsig.tools.dataTypes.DataTypesManager;
52
import org.gvsig.tools.dataTypes.impl.DefaultDataTypesManager;
53
import org.gvsig.tools.dynobject.DelegatedDynObject;
54
import org.gvsig.tools.dynobject.DynStruct;
55
import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException;
56
import org.gvsig.tools.locator.LocatorException;
57
import org.slf4j.Logger;
58
import org.slf4j.LoggerFactory;
59

  
60
/**
61
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
62
 */
63
public class GPEStoreParameters extends AbstractDataParameters implements
64
OpenFeatureStoreParameters, FilesystemStoreParameters,
65
NewFeatureStoreParameters {
66

  
67
    public static final String PARAMETERS_DEFINITION_NAME = "GPEStoreParameters";
68

  
69
    private static final String FILE_PARAMETER_NAME = "File";
70
    private static final String CRS_PARAMETER_NAME = "CRS";
71
    private static final String ENVELOPE_PARAMETER_NAME = "Envelope";
72
    private static final String FEATURETYPE_PARAMETER_NAME = "FeatureType";
73

  
74
    private DelegatedDynObject parameters;
75

  
76
    private static Logger logger = LoggerFactory.getLogger(GPEStoreParameters.class);
77

  
78
    public GPEStoreParameters() {
79
        this(PARAMETERS_DEFINITION_NAME);
80
    }
81

  
82
    protected GPEStoreParameters(String parametersDefinitionName) {
83
        this(parametersDefinitionName, GPEStoreProvider.NAME);
84
    }
85

  
86
    public GPEStoreParameters(String parametersDefinitionName, String name) {
87
        super();
88
        this.parameters = (DelegatedDynObject) FileHelper.newParameters(parametersDefinitionName);
89
        this.setDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME, name);
90
    }
91

  
92
    protected static void registerParametersDefinition(){
93
        DynStruct dynStruct = FileHelper.registerParametersDefinition(
94
            GPEStoreParameters.PARAMETERS_DEFINITION_NAME,
95
            GPEStoreParameters.class, "GPEParameters.xml");
96

  
97
        dynStruct.addDynFieldObject(ENVELOPE_PARAMETER_NAME).
98
        setClassOfValue(Envelope.class).setMandatory(false);
99

  
100
        dynStruct.addDynFieldObject(FEATURETYPE_PARAMETER_NAME).
101
        setClassOfValue(FeatureType.class).setMandatory(false);
102
    }
103

  
104
    protected DelegatedDynObject getDelegatedDynObject() {
105
        return parameters;
106
    }
107

  
108
    public String getDataStoreName() {
109
        return GPEStoreProvider.NAME;
110
    }
111

  
112
    public String getDescription() {
113
        return GPEStoreProvider.DESCRIPTION;
114
    }
115

  
116
    public boolean isValid() {
117
        return (this.getFile() != null);
118
    }
119

  
120
    public File getFile() {
121
        return (File) this.getDynValue(FILE_PARAMETER_NAME);
122
    }
123

  
124
    public void setFile(File file) {
125
        this.setDynValue(FILE_PARAMETER_NAME, file);
126
    }
127

  
128
    public String getFileName() {
129
        return this.getFile().getAbsolutePath();
130
    }
131

  
132
    public void setFileName(String fileName) {
133
        this.setDynValue(FILE_PARAMETER_NAME, fileName);
134
    }
135

  
136
    public IProjection getCRS() {
137
        return (IProjection) this.getDynValue(CRS_PARAMETER_NAME);
138
    }
139

  
140
    public void setCRS(IProjection srs) {
141
        this.setDynValue(CRS_PARAMETER_NAME, srs);
142
    }
143

  
144
    public void setCRS(String srs) {
145
        this.setDynValue(CRS_PARAMETER_NAME, srs);
146
    }
147

  
148
    public Envelope getEnvelope() {
149
        return (Envelope) this.getDynValue(ENVELOPE_PARAMETER_NAME);
150
    }
151

  
152
    public void setEnvelope(Envelope envelope) {
153
        this.setDynValue(ENVELOPE_PARAMETER_NAME, envelope);
154
    }
155

  
156
    public void setDynValue(String name, Object val) {
157
    	super.setDynValue(name, val);
158
    }
159

  
160
    public boolean getUseAxisOrderYX()  {
161
        boolean x = BooleanUtils.isTrue((Boolean) this.getDynValue("useAxisOrderYX"));
162
        return x;
163
    }
164

  
165
	public EditableFeatureType getDefaultFeatureType() {
166
		return (EditableFeatureType) this.getDynValue(FEATURETYPE_PARAMETER_NAME);
167
	}
168

  
169
	public void setDefaultFeatureType(FeatureType featureType) {
170
		this.setDynValue(FEATURETYPE_PARAMETER_NAME, featureType);
171
	}
172

  
173
    public Object getDynValue(String name) throws DynFieldNotFoundException {
174
        if (DataStore.METADATA_CRS.equalsIgnoreCase(name)) {
175
            try {
176
                GPEManager gpeManager=GPELocator.getGPEManager();
177
                String crs=gpeManager.getDefaultProjection(getFile());
178
                DataTypesManager dataTypesManager=ToolsLocator.getDataTypesManager();
179
                IProjection projection=(IProjection) dataTypesManager.coerce(org.cresques.DataTypes.CRS, crs);
180
                if (projection!=null){
181
                    setCRS(projection);
182
                }
183
            } catch (LocatorException  | ParserCreationException | CoercionException e) {
184
                logger.warn("Couldn't get default projection",e);
185
            }
186
        }
187
        return super.getDynValue(name);
188
    }
189
}
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.86/org.gvsig.gpe.app/org.gvsig.gpe.app.mainplugin/src/main/java/org/gvsig/fmap/dal/store/gpe/handlers/FmapContentHandlerCreationException.java
1
package org.gvsig.fmap.dal.store.gpe.handlers;
2

  
3
import java.util.HashMap;
4
import java.util.Map;
5

  
6
import org.gvsig.tools.exception.BaseException;
7

  
8
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
9
 *
10
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
11
 *
12
 * This program is free software; you can redistribute it and/or
13
 * modify it under the terms of the GNU General Public License
14
 * as published by the Free Software Foundation; either version 2
15
 * of the License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU General Public License
23
 * along with this program; if not, write to the Free Software
24
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
25
 *
26
 * For more information, contact:
27
 *
28
 *  Generalitat Valenciana
29
 *   Conselleria d'Infraestructures i Transport
30
 *   Av. Blasco Ib??ez, 50
31
 *   46010 VALENCIA
32
 *   SPAIN
33
 *
34
 *      +34 963862235
35
 *   gvsig@gva.es
36
 *      www.gvsig.gva.es
37
 *
38
 *    or
39
 *
40
 *   IVER T.I. S.A
41
 *   Salamanca 50
42
 *   46005 Valencia
43
 *   Spain
44
 *
45
 *   +34 963163400
46
 *   dac@iver.es
47
 */
48
/* CVS MESSAGES:
49
 *
50
 * $Id$
51
 * $Log$
52
 *
53
 */
54
/**
55
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
56
 */
57
public class FmapContentHandlerCreationException extends BaseException{
58
	private static final long serialVersionUID = -6021604626521668293L;
59
	
60
	public FmapContentHandlerCreationException(){
61
		initialize();
62
	}
63
	
64
	public FmapContentHandlerCreationException(Throwable e){
65
		initialize();
66
		initCause(e);
67
	}
68
	
69
	protected Map values() {
70
		return new HashMap();
71
	}
72
	
73
	/**
74
	 * Initialize the properties
75
	 */
76
	private void initialize() {
77
		messageKey = "gpe_lgvsig_contentHandler_error";
78
		formatString = "Error creating the contentHandler for" +
79
				"Fmap";
80
		code = serialVersionUID;
81
	}
82

  
83
}
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.86/org.gvsig.gpe.app/org.gvsig.gpe.app.mainplugin/src/main/java/org/gvsig/fmap/dal/store/gpe/handlers/FmapErrorHandler.java
1
package org.gvsig.fmap.dal.store.gpe.handlers;
2

  
3
import org.gvsig.gpe.lib.impl.parser.GPEErrorHandler;
4

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

  
56
}
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.86/org.gvsig.gpe.app/org.gvsig.gpe.app.mainplugin/src/main/java/org/gvsig/fmap/dal/store/gpe/handlers/FmapContentHandler.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19

  
20
package org.gvsig.fmap.dal.store.gpe.handlers;
21

  
22
import java.io.File;
23
import java.io.IOException;
24
import java.util.ArrayList;
25
import java.util.HashMap;
26
import java.util.Iterator;
27
import java.util.List;
28
import java.util.Map;
29

  
30
import org.cresques.cts.IProjection;
31
import org.gvsig.fmap.dal.DataTypes;
32
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
33
import org.gvsig.fmap.dal.feature.EditableFeatureType;
34
import org.gvsig.fmap.dal.feature.Feature;
35
import org.gvsig.fmap.dal.feature.FeatureType;
36
import org.gvsig.fmap.dal.feature.spi.DefaultFeatureProvider;
37
import org.gvsig.fmap.dal.feature.spi.FeatureProvider;
38
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProviderServices;
39
import org.gvsig.fmap.dal.store.gpe.GPEStoreProvider;
40
import org.gvsig.fmap.dal.store.gpe.model.GPEElement;
41
import org.gvsig.fmap.dal.store.gpe.model.GPEFeature;
42
import org.gvsig.fmap.geom.Geometry;
43
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
44
import org.gvsig.fmap.geom.Geometry.TYPES;
45
import org.gvsig.fmap.geom.GeometryLocator;
46
import org.gvsig.fmap.geom.GeometryManager;
47
import org.gvsig.fmap.geom.aggregate.MultiCurve;
48
import org.gvsig.fmap.geom.aggregate.MultiLine;
49
import org.gvsig.fmap.geom.aggregate.MultiPoint;
50
import org.gvsig.fmap.geom.aggregate.MultiPolygon;
51
import org.gvsig.fmap.geom.exception.CreateEnvelopeException;
52
import org.gvsig.fmap.geom.exception.CreateGeometryException;
53
import org.gvsig.fmap.geom.primitive.Curve;
54
import org.gvsig.fmap.geom.primitive.Envelope;
55
import org.gvsig.fmap.geom.primitive.Line;
56
import org.gvsig.fmap.geom.primitive.Point;
57
import org.gvsig.fmap.geom.primitive.Polygon;
58
import org.gvsig.fmap.geom.primitive.Ring;
59
import org.gvsig.gpe.lib.api.parser.IAttributesIterator;
60
import org.gvsig.gpe.lib.api.parser.ICoordinateIterator;
61
import org.gvsig.gpe.lib.api.parser.IGPEErrorHandler;
62
import org.gvsig.gpe.lib.impl.parser.GPEContentHandler;
63
import org.jfree.util.Log;
64
import org.slf4j.Logger;
65
import org.slf4j.LoggerFactory;
66

  
67

  
68

  
69
public class FmapContentHandler extends GPEContentHandler {
70
    private static final Logger LOG = LoggerFactory.getLogger(FmapContentHandler.class);
71

  
72
    private HashMap featureSet = null;
73
    private EditableFeatureType featureType = null;
74
    private FeatureStoreProviderServices store = null;
75
    private GPEStoreProvider storeProvider = null;
76
    private GeometryManager geomManager = GeometryLocator.getGeometryManager();
77
    private int featureId = 0;
78
    private Envelope envelope = null;
79
    private File file = null;
80
    private IProjection srs = null;
81
    private int geometryType = 0;
82
    private boolean useAxisOrderYX = false;
83

  
84
    public FmapContentHandler(IGPEErrorHandler errorHandler, FeatureStoreProviderServices store,
85
        GPEStoreProvider storeProvider, File file, IProjection srs, int geometryType) {
86
        super();
87
        setErrorHandler(errorHandler);
88
        this.store = store;
89
        this.storeProvider = storeProvider;
90
        this.file = file;
91
        this.srs = srs;
92
        this.geometryType = geometryType;
93
    }
94

  
95
    public FmapContentHandler(IGPEErrorHandler errorHandler, FeatureStoreProviderServices store,
96
        GPEStoreProvider storeProvider, File file, IProjection srs, int geometryType,
97
        boolean useAxisOrderYX) {
98
        this(errorHandler, store, storeProvider, file, srs, geometryType);
99
        this.useAxisOrderYX = useAxisOrderYX;
100
    }
101

  
102
    public int getFeaturesCount(){
103
        return featureSet.size();
104
    }
105

  
106
    public Feature getFeatureAt(int index){
107
        return (Feature)featureSet.get(new Integer(index));
108
    }
109

  
110
    public EditableFeatureType getFeatureType(){
111
        return featureType;
112
    }
113

  
114

  
115
    /**
116
     * @return the featureSet
117
     */
118
    public HashMap getFeatureSet() {
119
        return featureSet;
120
    }
121

  
122
    /*
123
     * (non-Javadoc)
124
     * @see org.gvsig.gpe.parser.GPEContentHandler#startLayer(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.gvsig.gpe.parser.IAttributesIterator, java.lang.Object, java.lang.Object)
125
     */
126
    public Object startLayer(String id, String namespace, String name,
127
        String description, String srs, IAttributesIterator iterator, Object parentLayer, Object box) {
128
        if (featureSet == null){
129
            featureSet = new HashMap();
130
        }
131
        if (envelope == null){
132
            try {
133
                envelope = geomManager.createEnvelope(SUBTYPES.GEOM2D);
134
            } catch (CreateEnvelopeException e) {
135
                Log.error("Error creating the envelope", e);
136
            }
137
        }
138
        return featureSet;
139
    }
140

  
141
    /*
142
     * (non-Javadoc)
143
     * @see org.gvsig.gpe.IGPEContentHandler#endLayer(java.lang.Object)
144
     */
145
    public void endLayer(Object layer) {
146
        if (featureType == null){
147
            createFeatureType(null);
148
        }
149
        storeProvider.setEnvelope(envelope);
150
    }
151

  
152
    /*
153
     * (non-Javadoc)
154
     * @see org.gvsig.gpe.parser.GPEContentHandler#startPoint(java.lang.String, org.gvsig.gpe.parser.ICoordinateIterator, java.lang.String)
155
     */
156
    public Object startPoint(String id, ICoordinateIterator coords, String srs) {
157
        return createPoint(coords);
158
    }
159

  
160
    private Point createPoint(ICoordinateIterator coords){
161
        double[] buffer = new double[coords.getDimension()];
162
        try {
163
            coords.hasNext();
164
            coords.next(buffer);
165
            Point point = null;
166
            if (buffer.length == 2){
167
                point = (Point) geomManager.create(TYPES.POINT, SUBTYPES.GEOM2D);
168
                if( useAxisOrderYX ) {
169
                    point.setX(buffer[1]);
170
                    point.setY(buffer[0]);
171
                } else {
172
                    point.setX(buffer[0]);
173
                    point.setY(buffer[1]);
174
                }
175
            }else if (buffer.length == 3){
176
                point = (Point) geomManager.create(TYPES.POINT, SUBTYPES.GEOM3D);
177
                if( useAxisOrderYX ) {
178
                    point.setX(buffer[1]);
179
                    point.setY(buffer[0]);
180
                } else {
181
                    point.setX(buffer[0]);
182
                    point.setY(buffer[1]);
183
                }
184
                point.setCoordinateAt(2, buffer[2]);
185
            }
186
            return point;
187
        } catch (IOException e) {
188
            getErrorHandler().addError(e);
189
        } catch (CreateGeometryException e) {
190
            getErrorHandler().addError(e);
191
        }
192
        return null;
193
    }
194

  
195
    private Point createPoint(double[] buffer){
196
        try {
197
            Point point = null;
198
            if (buffer.length == 2){
199
                point = (Point) geomManager.create(TYPES.POINT, SUBTYPES.GEOM2D);
200
                if( useAxisOrderYX ) {
201
                    point.setX(buffer[1]);
202
                    point.setY(buffer[0]);
203
                } else {
204
                    point.setX(buffer[0]);
205
                    point.setY(buffer[1]);
206
                }
207
            }else if (buffer.length == 3){
208
                point = (Point) geomManager.create(TYPES.POINT, SUBTYPES.GEOM3D);
209
                if( useAxisOrderYX ) {
210
                    point.setX(buffer[1]);
211
                    point.setY(buffer[0]);
212
                } else {
213
                    point.setX(buffer[0]);
214
                    point.setY(buffer[1]);
215
                }
216
                point.setCoordinateAt(2, buffer[2]);
217
            }
218
            return point;
219
        }catch (CreateGeometryException e) {
220
            getErrorHandler().addError(e);
221
        }
222
        return null;
223
    }
224

  
225

  
226
    /* (non-Javadoc)
227
     * @see org.gvsig.gpe.parser.GPEContentHandler#startLineString(java.lang.String, org.gvsig.gpe.parser.ICoordinateIterator, java.lang.String)
228
     */
229
    public Object startLineString(String id, ICoordinateIterator coords,
230
        String srs) {
231
        return createCurve(coords);
232
    }
233

  
234
    private Line createCurve(ICoordinateIterator coords){
235
//        GeneralPathX gp = createGeneralPathX(coords);
236
        try {
237
            Line curve = null;
238
            if (coords == null || coords.getDimension() == 2){
239
                curve = (Line) geomManager.create(TYPES.LINE, SUBTYPES.GEOM2D);
240
            }else if (coords.getDimension() == 3){
241
                curve = (Line) geomManager.create(TYPES.LINE, SUBTYPES.GEOM3D);
242
            }
243
            while (coords.hasNext()){
244
                Point point=createPoint(coords);
245
                curve.addVertex(point);
246
            }
247
//            curve.setGeneralPath(gp);
248
            return curve;
249
        } catch (CreateGeometryException e) {
250
            getErrorHandler().addError(e);
251
        } catch (IOException e) {
252
            getErrorHandler().addError(e);
253
        }
254
        return null;
255
    }
256

  
257
//    private GeneralPathX createGeneralPathX(ICoordinateIterator coords){
258
//        GeneralPathX gp = new GeneralPathX();
259
//        if (coords == null){
260
//            return gp;
261
//        }
262
//        double[] buffer = new double[coords.getDimension()];
263
//        try {
264
//            if (coords.hasNext()){
265
//                coords.next(buffer);
266
//                if( this.useAxisOrderYX ) {
267
//                    gp.moveTo(buffer[1], buffer[0]);
268
//                } else {
269
//                    gp.moveTo(buffer[0], buffer[1]);
270
//                }
271
//            }
272
//            while(coords.hasNext()){
273
//                coords.next(buffer);
274
//                if( this.useAxisOrderYX ) {
275
//                    gp.lineTo(buffer[1], buffer[0]);
276
//                } else {
277
//                    gp.lineTo(buffer[0], buffer[1]);
278
//                }
279
//            }
280
//        } catch (IOException e) {
281
//            getErrorHandler().addError(e);
282
//        }
283
//        return gp;
284
//    }
285

  
286
    /* (non-Javadoc)
287
     * @see org.gvsig.gpe.parser.GPEContentHandler#startPolygon(java.lang.String, org.gvsig.gpe.parser.ICoordinateIterator, java.lang.String)
288
     */
289

  
290
    public Object startPolygon(String id, ICoordinateIterator coords, String srs) {
291
        return createPolygon(coords);
292
    }
293

  
294
    private Polygon createPolygon(ICoordinateIterator coords){
295
//        GeneralPathX gp = createGeneralPathX(coords);
296
        try {
297
            Polygon polygon = null;
298
            if (coords.getDimension() == 2){
299
                polygon = (Polygon) geomManager.create(TYPES.POLYGON, SUBTYPES.GEOM2D);
300
            }else if (coords.getDimension() == 3){
301
                polygon = (Polygon) geomManager.create(TYPES.POLYGON, SUBTYPES.GEOM3D);
302
            }
303
            //surface.setGeneralPath(gp);
304
            while (coords.hasNext()){
305
                Point point=createPoint(coords);
306
                polygon.addVertex(point);
307
            }
308
            if (!polygon.getVertex(0).equals(polygon.getVertex(polygon.getNumVertices()-1))){
309
                polygon.addVertex(polygon.getVertex(0));
310
            }
311

  
312
            return polygon;
313
        } catch (CreateGeometryException e) {
314
            getErrorHandler().addError(e);
315
        } catch (IOException e) {
316
            getErrorHandler().addError(e);
317
        }
318
        return null;
319
    }
320

  
321

  
322
    /* (non-Javadoc)
323
     * @see org.gvsig.gpe.parser.GPEContentHandler#startInnerPolygon(java.lang.String, org.gvsig.gpe.parser.ICoordinateIterator, java.lang.String)
324
     */
325
    public Object startInnerPolygon(String id, ICoordinateIterator coords,
326
        String srs) {
327
        return createPolygon(coords);
328
    }
329

  
330
    /*
331
     * (non-Javadoc)
332
     * @see org.gvsig.gpe.IGPEContentHandler#addGeometryToFeature(java.lang.Object, java.lang.Object)
333
     */
334
    public void addGeometryToFeature(Object geometry, Object feature) {
335

  
336
        /*
337
         * Two geometries (possibly of different type) in the same feature
338
         * Instead of overwriting we will preserve the first that arrives.
339
         * Alternative: aggregate, but then gvSIG would have issues to
340
         * draw? or export?
341
         */
342
        GPEFeature gpe_feat = (GPEFeature) feature;
343
        Geometry geom = gpe_feat.getGeometry();
344
        if (geom == null ||
345
            geom.getGeometryType().getType() == Geometry.TYPES.NULL) {
346

  
347
            gpe_feat.setGeometry((Geometry)geometry);
348
        }
349
    }
350

  
351
    /*
352
     * (non-Javadoc)
353
     * @see org.gvsig.gpe.IGPEContentHandler#addBboxToLayer(java.lang.Object, java.lang.Object)
354
     */
355
    public void addBboxToLayer(Object bbox, Object layer) {
356
        //		if (layer != null){
357
        //		GPEBBox gpeBBox = (GPEBBox)bbox;
358
        //		if (gpeBBox.getSrs() != null){
359
        //		IProjection projection = null;
360
        //		try{
361
        //		CRSFactory.getCRS(gpeBBox.getSrs());
362
        //		}catch(Exception e){
363
        //		//If the CRS factory has an error.
364
        //		}
365
        //		if ((projection != null) && (!(projection.equals(((FLayer)layer).getProjection())))){
366
        //		//TODO reproyectar la bbox y asignarsela a la capa
367
        //		}
368
        //		}
369
        //		((IGPEDriver)layer).setExtent(gpeBBox.getBbox2D());
370
        //		}
371
    }
372

  
373
    /*
374
     * (non-Javadoc)
375
     * @see org.gvsig.gpe.IGPEContentHandler#addElementToFeature(java.lang.Object, java.lang.Object)
376
     */
377
    public void addElementToFeature(Object element, Object feature) {
378
        GPEElement gpeElement = (GPEElement)element;
379
        ((GPEFeature)feature).addElement(gpeElement);
380
    }
381

  
382
    /*
383
     * (non-Javadoc)
384
     * @see org.gvsig.gpe.IGPEContentHandler#addFeatureToLayer(java.lang.Object, java.lang.Object)
385
     */
386
    public void addFeatureToLayer(Object feature, Object layer) {
387
        GPEFeature gpefeature = (GPEFeature)feature;
388
        Envelope currentEnvelope = gpefeature.getEnvelope();
389
        if (featureType == null){
390
            createFeatureType(gpefeature);
391

  
392
            //Initialize the envelope
393
            try {
394
                envelope = geomManager.createEnvelope(SUBTYPES.GEOM2D);
395
            } catch (CreateEnvelopeException e) {
396
                getErrorHandler().addError(e);
397
            }
398
            //Calculates the envelope
399
            envelope = currentEnvelope;
400
        }else{
401
            //Calculates the envelope
402
            if (currentEnvelope != null){
403
                envelope.add(currentEnvelope);
404
            }
405
        }
406
        //If it is null is a multilayer: not supported yet
407
        if (layer != null){
408
            FeatureProvider data = new DefaultFeatureProvider(featureType.getNotEditableCopy(), storeProvider.createNewOID());
409
            Map elements = gpefeature.getelements();
410
            Iterator keys = elements.keySet().iterator();
411
            String gid = gpefeature.getId();
412
            data.setOID(gid);
413
            while (keys.hasNext()){
414
                String elementName = (String)keys.next();
415
                if (featureType.getIndex(elementName) != -1) {
416
                    /*
417
                     * If attribute exists, set its value
418
                     * (if a field description was not properly parsed in the
419
                     * feature type description (previous http request) then
420
                     * perhaps it's not available in featureType)
421
                     */
422
                    data.set(elementName, ((GPEElement)elements.get(elementName)).getValue());
423
                }
424
            }
425
            data.setDefaultGeometry(gpefeature.getGeometry());
426
            data.set(featureType.getDefaultGeometryAttributeIndex(), gpefeature.getGeometry());
427
            ((HashMap)layer).put(gid, data);
428
        }
429
    }
430

  
431
    private void createFeatureType(GPEFeature gpefeature){
432
        featureType = store.createFeatureType();
433

  
434
        //Adding the Geometry field
435
        EditableFeatureAttributeDescriptor attributeDescriptor = featureType.add("the_geom", DataTypes.GEOMETRY).setGeometryType(geometryType);
436
        attributeDescriptor.setGeometrySubType(SUBTYPES.GEOM2D);
437
        attributeDescriptor.setSRS(srs);
438
        featureType.setDefaultGeometryAttributeName("the_geom");
439

  
440
        //Adding the ID
441
        EditableFeatureAttributeDescriptor ed = featureType.add("gid", DataTypes.LONG);
442
        ed.setSize(10);
443

  
444
        featureType.setHasOID(true);
445

  
446
        if (gpefeature != null){
447
            Map elements = gpefeature.getelements();
448
            Iterator keys = elements.keySet().iterator();
449
            while (keys.hasNext()){
450
                String elementName = (String)keys.next();
451
                if (!elementName.equals("the_geom") && !elementName.equals("gid")){
452
                    ed = featureType.add(elementName, DataTypes.STRING);
453
                    ed.setSize(80);
454
                }
455
            }
456
        }
457

  
458
        FeatureType defaultType = featureType.getNotEditableCopy();
459
        List types = new ArrayList(1);
460
        types.add(defaultType);
461
        this.store.setFeatureTypes(types, defaultType);
462
    }
463

  
464
    /*
465
     * (non-Javadoc)
466
     * @see org.gvsig.gpe.IGPEContentHandler#addInnerPolygonToPolygon(java.lang.Object, java.lang.Object)
467
     */
468
    public void addInnerPolygonToPolygon(Object innerPolygon, Object Polygon) {
469
        //((Geometry)Polygon).addGeometry((GPEGeometry)innerPolygon);
470
    }
471

  
472
    /*
473
     * (non-Javadoc)
474
     * @see org.gvsig.gpe.IGPEContentHandler#addNameToFeature(java.lang.String, java.lang.Object)
475
     */
476
    public void addNameToFeature(String name, Object feature) {
477

  
478
    }
479

  
480
    /*
481
     * (non-Javadoc)
482
     * @see org.gvsig.gpe.IGPEContentHandler#addParentElementToElement(java.lang.Object, java.lang.Object)
483
     */
484
    public void addParentElementToElement(Object parent, Object element) {
485

  
486
    }
487

  
488
    /*
489
     * (non-Javadoc)
490
     * @see org.gvsig.gpe.IGPEContentHandler#addSrsToLayer(java.lang.String, java.lang.Object)
491
     */
492
    public void addSrsToLayer(String srs, Object Layer) {
493
        //		this.srs = srs;
494
    }
495

  
496

  
497
    /* (non-Javadoc)
498
     * @see org.gvsig.gpe.parser.GPEContentHandler#startBbox(java.lang.String, org.gvsig.gpe.parser.ICoordinateIterator, java.lang.String)
499
     */
500
    public Object startBbox(String id, ICoordinateIterator coords, String srs) {
501
        Envelope envelope = null;
502
        try {
503
            if (coords.getDimension() == 2){
504
                envelope = geomManager.createEnvelope(SUBTYPES.GEOM2D);
505
            }else if (coords.getDimension() == 3){
506
                envelope = geomManager.createEnvelope(SUBTYPES.GEOM3D);
507
            }
508
            double[] buffer = new double[coords.getDimension()];
509

  
510
            if (coords.hasNext()){
511
                coords.next(buffer);
512
                envelope.setLowerCorner(createPoint(buffer));
513
            }
514
            if (coords.hasNext()){
515
                coords.next(buffer);
516
                envelope.setUpperCorner(createPoint(buffer));
517
            }
518
        } catch (IOException e) {
519
            getErrorHandler().addError(e);
520
        } catch (CreateEnvelopeException e) {
521
            getErrorHandler().addError(e);
522
        }
523
        return envelope;
524
    }
525

  
526
    /*
527
     * (non-Javadoc)
528
     * @see org.gvsig.gpe.parser.GPEContentHandler#startElement(java.lang.String, java.lang.String, java.lang.Object, org.gvsig.gpe.parser.IAttributesIterator, java.lang.Object)
529
     */
530
    public Object startElement(String namespace, String name, Object value,
531
        IAttributesIterator attributesIterator,	Object parentElement) {
532
        return new GPEElement(name, value, (GPEElement)parentElement);
533
    }
534

  
535
    /*
536
     * (non-Javadoc)
537
     * @see org.gvsig.gpe.parser.GPEContentHandler#startFeature(java.lang.String, java.lang.String, java.lang.String, org.gvsig.gpe.parser.IAttributesIterator, java.lang.Object)
538
     */
539
    public Object startFeature(String id, String namespace, String name,
540
        IAttributesIterator attributes, Object layer){
541
        String sId;
542
        if (id == null){
543
            sId = new String(new Long(featureId).toString());
544
        }else{
545
            sId = id;
546
        }
547
        featureId++;
548
        //Check the xml schema...
549
        //		for (int i=0 ; i<schemas.size() ; i++){
550
        //			IXSSchema schema = schemas.get(i);
551
        //			IXSElementDeclaration element = schema.getElementDeclarationByName(namespace, name);
552
        //			if (element != null){
553
        //				featureType = store.createFeatureType();
554
        //				IXSTypeDefinition type = element.getTypeDefinition();
555
        //				if (type instanceof IXSComplexTypeDefinition){
556
        //					IXSComplexTypeDefinition complexType = (IXSComplexTypeDefinition)type;
557
        //					complexType.getContentType().
558
        //				}
559
        //
560
        //				featureType.add("the_geom", DataTypes.GEOMETRY).setGeometryType(TYPES.GEOMETRY);
561
        //				featureType.setDefaultGeometryAttributeName("the_geom");
562
        //				featureType.setHasOID(true);
563
        //				while (keys.hasNext()){
564
        //					String elementName = (String)keys.next();
565
        //					featureType.add(elementName, DataTypes.STRING);
566
        //				}
567
        //				FeatureType defaultType = featureType.getNotEditableCopy();
568
        //				List types = new ArrayList(1);
569
        //				types.add(defaultType);
570
        //				this.store.setFeatureTypes(types, defaultType);
571
        //
572
        //				//Initialize the envelope
573
        //				try {
574
        //					envelope = geomManager.createEnvelope(SUBTYPES.GEOM2D);
575
        //				} catch (CreateEnvelopeException e) {
576
        //					getErrorHandler().addError(e);
577
        //				}
578
        //			}
579
        //		}
580
        return new GPEFeature(sId,
581
            name, name);
582
    }
583

  
584
    /* (non-Javadoc)
585
     * @see org.gvsig.gpe.parser.GPEContentHandler#startLinearRing(java.lang.String, org.gvsig.gpe.parser.ICoordinateIterator, java.lang.String)
586
     */
587
    public Object startLinearRing(String id, ICoordinateIterator coords,
588
        String srs) {
589
        return createPolygon(coords);
590
    }
591

  
592
    /*
593
     * (non-Javadoc)
594
     * @see org.gvsig.gpe.IGPEContentHandler#startMultiPoint(java.lang.String, java.lang.String)
595
     */
596
    public Object startMultiPoint(String id, String srs, int dimension) {
597
        try {
598
            return geomManager.create(TYPES.MULTIPOINT, getGeometrySubtype(dimension));
599
        } catch (CreateGeometryException e) {
600
            getErrorHandler().addError(e);
601
        }
602
        return null;
603
    }
604

  
605
    /*
606
     * (non-Javadoc)
607
     * @see org.gvsig.gpe.IGPEContentHandler#startMultiPoint(java.lang.String, java.lang.String)
608
     */
609
    public Object startMultiPoint(String id, String srs) {
610
        try {
611
            return geomManager.create(TYPES.MULTIPOINT, Geometry.SUBTYPES.GEOM2D);
612
        } catch (CreateGeometryException e) {
613
            getErrorHandler().addError(e);
614
        }
615
        return null;
616
    }
617

  
618
    /*
619
     * (non-Javadoc)
620
     * @see org.gvsig.gpe.IGPEContentHandler#addPointToMultiPoint(java.lang.Object, java.lang.Object)
621
     */
622
    public void addPointToMultiPoint(Object point, Object multiPoint) {
623
        if (point instanceof Point){
624
            Point gPoint=(Point)point;
625
            if (gPoint.getGeometryType().isSubTypeOf( Geometry.SUBTYPES.GEOM3D)){
626
                try {
627
                    Point point2D=(Point)geomManager.create(TYPES.POINT, Geometry.SUBTYPES.GEOM2D);
628
                    point2D.setX(gPoint.getX());
629
                    point2D.setY(gPoint.getY());
630
                    ((MultiPoint)multiPoint).addPoint(point2D);
631
                } catch (CreateGeometryException e) {
632
                    getErrorHandler().addError(e);
633
                }
634
            }else{
635
                ((MultiPoint)multiPoint).addPoint((Point)point);
636
            }
637
        }
638
    }
639

  
640
    /*
641
     * (non-Javadoc)
642
     * @see org.gvsig.gpe.IGPEContentHandler#startMultiLineString(java.lang.String, java.lang.String)
643
     */
644
    public Object startMultiLineString(String id, String srs, int dimension) {
645
        super.startMultiLineString(id, srs);
646
        try {
647
            return geomManager.create(TYPES.MULTILINE, getGeometrySubtype(dimension));
648
        } catch (CreateGeometryException e) {
649
            getErrorHandler().addError(e);
650
        }
651
        return null;
652
    }
653

  
654
    /*
655
     * (non-Javadoc)
656
     * @see org.gvsig.gpe.IGPEContentHandler#startMultiLineString(java.lang.String, java.lang.String)
657
     */
658
    public Object startMultiLineString(String id, String srs) {
659
        return startMultiLineString (id,  srs, Geometry.SUBTYPES.GEOM2D);
660
    }
661

  
662
    /*
663
     * (non-Javadoc)
664
     * @see org.gvsig.gpe.IGPEContentHandler#addLineStringToMultiLineString(java.lang.Object, java.lang.Object)
665
     */
666
    public void addLineStringToMultiLineString(Object lineString, Object multiLineString) {
667
        if (lineString instanceof Line){
668
            Line gLine=(Line)lineString;
669
            if (gLine.getGeometryType().isSubTypeOf( Geometry.SUBTYPES.GEOM3D)){
670
                try {
671
                    Line line2D=(Line)geomManager.create(TYPES.LINE, Geometry.SUBTYPES.GEOM2D);
672
                    for(int i=0;i<gLine.getNumVertices();i++){
673
                        Point point2D=(Point)geomManager.create(TYPES.POINT, Geometry.SUBTYPES.GEOM2D);
674
                        Point point3D=gLine.getVertex(i);
675
                        point2D.setX(point3D.getX());
676
                        point2D.setY(point3D.getY());
677
                        line2D.addVertex(point2D);
678
                    }
679
                    ((MultiLine)multiLineString).addPrimitive(line2D);;
680
                } catch (CreateGeometryException e) {
681
                    getErrorHandler().addError(e);
682
                }
683
            }else{
684
                ((MultiLine)multiLineString).addPrimitive((Line)lineString);
685
            }
686
        }
687
    }
688

  
689
    /*
690
     * (non-Javadoc)
691
     * @see org.gvsig.gpe.IGPEContentHandler#startMultiPolygon(java.lang.String, java.lang.String)
692
     */
693
    public Object startMultiPolygon(String id, String srs, int dimension) {
694
        super.startMultiPolygon(id, srs);
695
        try {
696
            return geomManager.create(TYPES.MULTIPOLYGON, getGeometrySubtype(dimension));
697
        } catch (CreateGeometryException e) {
698
            getErrorHandler().addError(e);
699
        }
700
        return null;
701
    }
702

  
703
    /*
704
     * (non-Javadoc)
705
     * @see org.gvsig.gpe.IGPEContentHandler#startMultiPolygon(java.lang.String, java.lang.String)
706
     */
707
    public Object startMultiPolygon(String id, String srs) {
708
        return startMultiPolygon(id, srs, Geometry.SUBTYPES.GEOM2D);
709
    }
710

  
711
    /*
712
     * (non-Javadoc)
713
     * @see org.gvsig.gpe.IGPEContentHandler#addPolygonToMultiPolygon(java.lang.Object, java.lang.Object)
714
     */
715
    public void addPolygonToMultiPolygon(Object polygon, Object multiPolygon) {
716
        if (polygon instanceof Polygon){
717
            Polygon gPolygon=(Polygon)polygon;
718
            if (gPolygon.getGeometryType().isSubTypeOf( Geometry.SUBTYPES.GEOM3D)){
719
                try {
720
                    Polygon polygon2D=(Polygon)geomManager.create(TYPES.POLYGON, Geometry.SUBTYPES.GEOM2D);
721
                    for (int p=0;p<gPolygon.getNumVertices();p++){
722
                        Point point2D=(Point)geomManager.create(TYPES.POINT, Geometry.SUBTYPES.GEOM2D);
723
                        Point point3D=gPolygon.getVertex(p);
724
                        point2D.setX(point3D.getX());
725
                        point2D.setY(point3D.getY());
726
                        polygon2D.addVertex(point2D);
727
                    }
728
                    for (int r=0;r<gPolygon.getNumInteriorRings();r++){
729
                        Ring ring2D=(Ring)geomManager.create(TYPES.RING, Geometry.SUBTYPES.GEOM2D);
730
                        Ring ring3D=gPolygon.getInteriorRing(r);
731
                        for(int i=0;i<ring2D.getNumVertices();i++){
732
                            Point point2D=(Point)geomManager.create(TYPES.POINT, Geometry.SUBTYPES.GEOM2D);
733
                            Point point3D=ring3D.getVertex(i);
734
                            point2D.setX(point3D.getX());
735
                            point2D.setY(point3D.getY());
736
                            ring2D.addVertex(point2D);
737
                        }
738
                        polygon2D.addInteriorRing(ring2D);
739
                    }
740
                    ((MultiPolygon)multiPolygon).addPrimitive(polygon2D);
741
                } catch (CreateGeometryException e) {
742
                    getErrorHandler().addError(e);
743
                }
744
            }else{
745
                ((MultiPolygon)multiPolygon).addPrimitive((Polygon)polygon);
746
            }
747
        }
748
    }
749

  
750
    /* (non-Javadoc)
751
     * @see org.gvsig.gpe.GPEContentHandler#addCurveToMultiCurve(java.lang.Object, java.lang.Object)
752
     */
753
    public void addCurveToMultiCurve(Object curve, Object multiCurve) {
754
        //((MultiCurve)multiCurve).addCurve((Curve)curve);
755
        addLineStringToMultiLineString(curve, multiCurve);
756
    }
757

  
758
    /* (non-Javadoc)
759
     * @see org.gvsig.gpe.GPEContentHandler#addSegmentToCurve(java.lang.Object, java.lang.Object)
760
     */
761
    public void addSegmentToCurve(Object segment, Object curve) {
762
        if (segment instanceof Point) {
763
            ((Curve)curve).addVertex((Point) segment);
764
        } else {
765
            if (segment instanceof Curve) {
766
                Curve seg_cur = (Curve) segment;
767
                int n = seg_cur.getNumVertices();
768
                for (int i=0; i<n; i++) {
769
                    ((Curve)curve).addVertex(seg_cur.getVertex(i));
770
                }
771

  
772
            } else {
773
                LOG.info("Discarded unexpected geometry class: "
774
                    + (segment == null ? "NULL" : segment.getClass().getName()));
775
            }
776
        }
777

  
778
    }
779

  
780
    /* (non-Javadoc)
781
     * @see org.gvsig.gpe.parser.GPEContentHandler#startCurve(java.lang.String, org.gvsig.gpe.parser.ICoordinateIterator, java.lang.String)
782
     */
783
    public Object startCurve(String id, ICoordinateIterator coords, String srs) {
784
        return createCurve(coords);
785
    }
786

  
787
    /* (non-Javadoc)
788
     * @see org.gvsig.gpe.GPEContentHandler#startCurve(java.lang.String, java.lang.String)
789
     */
790
    public Object startCurve(String id, String srs) {
791
        return createCurve(null);
792
    }
793

  
794
    /* (non-Javadoc)
795
     * @see org.gvsig.gpe.GPEContentHandler#startMultiCurve(java.lang.String, java.lang.String)
796
     */
797
    public Object startMultiCurve(String id, String srs, int dimension) {
798
        try {
799
            return geomManager.create(TYPES.MULTILINE, getGeometrySubtype(dimension));
800
        } catch (CreateGeometryException e) {
801
            getErrorHandler().addError(e);
802
        }
803
        return null;
804
    }
805

  
806
    /* (non-Javadoc)
807
     * @see org.gvsig.gpe.GPEContentHandler#startMultiCurve(java.lang.String, java.lang.String)
808
     */
809
    public Object startMultiCurve(String id, String srs) {
810
        return startMultiCurve(id,srs,Geometry.SUBTYPES.GEOM2D);
811
    }
812

  
813
    /* (non-Javadoc)
814
     * @see org.gvsig.gpe.GPEContentHandler#addGeometryToMultiGeometry(java.lang.Object, java.lang.Object)
815
     */
816
    public void addGeometryToMultiGeometry(Object geometry, Object multiGeometry) {
817
        if (((Geometry)multiGeometry).getGeometryType().isTypeOf(TYPES.MULTILINE) ){
818
            ((MultiLine)multiGeometry).addPrimitive((Line)geometry);
819
        }
820
        if (((Geometry)multiGeometry).getGeometryType().isTypeOf(TYPES.MULTIPOINT) ){
821
            ((MultiPoint)multiGeometry).addPrimitive((Point)geometry);
822
        }
823
        if (((Geometry)multiGeometry).getGeometryType().isTypeOf(TYPES.MULTIPOLYGON) ){
824
            ((MultiPolygon)multiGeometry).addPrimitive((Polygon)geometry);
825
        }
826
    }
827

  
828
    /* (non-Javadoc)
829
     * @see org.gvsig.gpe.GPEContentHandler#startMultiGeometry(java.lang.String, java.lang.String)
830
     */
831
    public Object startMultiGeometry(String id, String srs) {
832
//        try {
833
//            return geomManager.create(TYPES.AGGREGATE, SUBTYPES.GEOM2D);
834
//        } catch (CreateGeometryException e) {
835
//            getErrorHandler().addError(e);
836
//        }
837
        return null;
838
    }
839

  
840
    /**
841
     * @return a new OID
842
     */
843
    public Object createNewOID() {
844
        featureId++;
845
        return String.valueOf(featureId);
846
    }
847

  
848
    /**
849
     * @param envelope the envelope to set
850
     */
851
    public void setEnvelope(Envelope envelope) {
852
        this.envelope = envelope;
853
    }
854

  
855
    /**
856
     * @param featureType the featureType to set
857
     */
858
    public void setFeatureType(EditableFeatureType featureType) {
859
        this.featureType = featureType;
860
    }
861

  
862
    private int getGeometrySubtype(int dimension) {
863
        switch(dimension) {
864
            case 3:
865
                 return Geometry.SUBTYPES.GEOM3D;
866
            default:
867
            case 2:
868
                 return Geometry.SUBTYPES.GEOM2D;
869
        }
870
    }
871
}
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.86/org.gvsig.gpe.app/org.gvsig.gpe.app.mainplugin/src/main/java/org/gvsig/fmap/dal/store/gpe/model/GPEElement.java
1
package org.gvsig.fmap.dal.store.gpe.model;
2

  
3
import java.util.HashMap;
4

  
5
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
6
 *
7
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
22
 *
23
 * For more information, contact:
24
 *
25
 *  Generalitat Valenciana
26
 *   Conselleria d'Infraestructures i Transport
27
 *   Av. Blasco Ib??ez, 50
28
 *   46010 VALENCIA
29
 *   SPAIN
30
 *
31
 *      +34 963862235
32
 *   gvsig@gva.es
33
 *      www.gvsig.gva.es
34
 *
35
 *    or
36
 *
37
 *   IVER T.I. S.A
38
 *   Salamanca 50
39
 *   46005 Valencia
40
 *   Spain
41
 *
42
 *   +34 963163400
43
 *   dac@iver.es
44
 */
45
/* CVS MESSAGES:
46
 *
47
 * $Id$
48
 * $Log$
49
 *
50
 */
51
/**
52
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
53
 */
54
public class GPEElement {
55
	private String name = null;
56
	private Object value = null;
57
	private HashMap subElements = null;
58
	
59
	public GPEElement(String name, Object value) {
60
		super();
61
		this.name = name;
62
		this.value = value;
63
		subElements = new HashMap();
64
	}
65
	
66
	public GPEElement(String name, Object value, GPEElement parentElement) {
67
		this(name,value);
68
		//If it is a complex value
69
		if (parentElement != null){
70
			parentElement.addChildElement(this);			
71
		}
72
	}	
73
	
74
	/**
75
	 * It adds a new child element
76
	 * @param children
77
	 * The element to add
78
	 */
79
	public void addChildElement(GPEElement children){
80
		subElements.put(children.getName(), children);
81
	}
82
	
83
	/**
84
	 * @return the name
85
	 */
86
	public String getName() {
87
		return name;
88
	}
89
	
90
	/**
91
	 * @return the value
92
	 */
93
	public Object getValue() {
94
		if (subElements.size() > 0){
95
//			ComplexValue cValue = ValueFactory.createComplexValue(name);
96
//			Iterator it = subElements.keySet().iterator();
97
//			while(it.hasNext()){
98
//				GPEElement element = (GPEElement)subElements.get(it.next());
99
//				cValue.put(element.getName(), element.getValue());
100
//			}
101
//			return cValue;
102
		}
103
		return value;		
104
	}
105
}
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.86/org.gvsig.gpe.app/org.gvsig.gpe.app.mainplugin/src/main/java/org/gvsig/fmap/dal/store/gpe/model/GPEFeature.java
1
package org.gvsig.fmap.dal.store.gpe.model;
2

  
3
import java.util.LinkedHashMap;
4

  
5
import org.gvsig.fmap.geom.Geometry;
6
import org.gvsig.fmap.geom.GeometryLocator;
7
import org.gvsig.fmap.geom.GeometryManager;
8
import org.gvsig.fmap.geom.exception.CreateGeometryException;
9
import org.gvsig.fmap.geom.primitive.Envelope;
10
import org.slf4j.Logger;
11
import org.slf4j.LoggerFactory;
12

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff