Index: DGNStoreProvider.java
===================================================================
--- DGNStoreProvider.java	(revision 129)
+++ DGNStoreProvider.java	(revision 130)
@@ -315,7 +315,7 @@
                     TimeCounter tc = new TimeCounter();
                     tc.start();
 
-                    FeatureStoreProviderServices store = getStoreServices();
+                    FeatureStoreProviderServices storeProviderServices = getStoreServices();
                     if (dgndata == null && !(getDGNParameters().useReload())) {
                         if (resource.getData() != null) {
                             dgndata =
@@ -333,7 +333,7 @@
                         data = dgndata.data;
                         counterNewsOIDs = 0;
                         Reader reader = new Reader().initialice(getMemoryProvider(), (File) resource.get(), projection, legendBuilder);
-                        reader.begin(store);
+                        reader.begin(storeProviderServices);
                         dgndata.defaultFType = reader.getDefaultType().getNotEditableCopy();
                         List types = new ArrayList();
                         Iterator it = reader.getTypes().iterator();
@@ -349,7 +349,7 @@
                         dgndata.fTypes = types;
 
                         resource.notifyOpen();
-                        store.setFeatureTypes(dgndata.fTypes, dgndata.defaultFType);
+                        storeProviderServices.setFeatureTypes(dgndata.fTypes, dgndata.defaultFType);
                         reader.load();
                         dgndata.envelope = reader.getEnvelope();
                         dgndata.legendBuilder = legendBuilder;
@@ -365,7 +365,7 @@
                     // El feature type no lo compartimos entre las instancias del
                     // mismo resource ya que puede cambiar en funcion del filtro.
                     // Por lo menos el geometry-type.
-                    List<FeatureType> featureTypes = getFeatureTypes(store);
+                    List<FeatureType> featureTypes = getFeatureTypes(storeProviderServices);
 
                     tc.restart("Created featuretype (featureTypes=" + featureTypes + ")");
 
@@ -380,7 +380,7 @@
                     tc.restart("PostProcessFeatures");
 
                     legendBuilder = dgndata.legendBuilder;
-                    store.setFeatureTypes(featureTypes, featureTypes.get(0));
+                    storeProviderServices.setFeatureTypes(featureTypes, featureTypes.get(0));
                     setDynValue("CRS", projection);
                     counterNewsOIDs = data.size();
                     tc.restart("load finished.");
@@ -420,6 +420,11 @@
     }
 
     public List getFeatureTypes(FeatureStoreProviderServices store) {
+        //FIXME: Habría que distinguir cuando se va a crear un DGN 3D o 2D, de momento siempre 3D
+        return getFeatureTypes(store, Geometry.SUBTYPES.GEOM3D);
+    }
+
+    private List getFeatureTypes(FeatureStoreProviderServices store, int subtype) {
         EditableFeatureType featureType = store.createFeatureType(getName());
 
         featureType.setHasOID(true);
@@ -539,10 +544,10 @@
         }
         try {
             attr.setGeometryType(GeometryLocator.getGeometryManager()
-                .getGeometryType(geometryTypeToUse, Geometry.SUBTYPES.GEOM3D));
+                .getGeometryType(geometryTypeToUse, subtype));
         } catch (Exception e) {
             attr.setGeometryType(geometryTypeToUse);
-            attr.setGeometrySubType(Geometry.SUBTYPES.GEOM3D);
+            attr.setGeometrySubType(subtype);
         }
         ID_FIELD_GEOMETRY = attr.getIndex();
 
@@ -562,17 +567,17 @@
         private IProjection projection;
         private List types;
         private LegendBuilder leyendBuilder;
-        private AbstractMemoryStoreProvider store;
+        private AbstractMemoryStoreProvider storeProvider;
         private Envelope envelope;
 
-        public Reader initialice(AbstractMemoryStoreProvider store, File file,
+        public Reader initialice(AbstractMemoryStoreProvider storeProvider, File file,
             IProjection projection, LegendBuilder leyendBuilder) {
-            this.store = store;
+            this.storeProvider = storeProvider;
             this.file = file;
             this.projection = projection;
             this.leyendBuilder = leyendBuilder;
             if (leyendBuilder != null) {
-                leyendBuilder.initialize(store);
+                leyendBuilder.initialize(storeProvider);
             }
             return this;
         }
@@ -581,9 +586,9 @@
             return this.envelope;
         }
 
-        public void begin(FeatureStoreProviderServices store) {
+        public void begin(FeatureStoreProviderServices storeProviderServices) {
 
-            types = getFeatureTypes(store);
+            types = getFeatureTypes(storeProviderServices);
 
             if (leyendBuilder != null) {
                 leyendBuilder.begin();
@@ -653,12 +658,14 @@
 
                 DGNReader dgnReader = new DGNReader(file.getAbsolutePath(), getDGNParameters().logErrors());
 
-                if (dgnReader.getInfo().dimension == 2 || getDGNParameters().ignoreZs()) {
-                    envelope = geomManager.createEnvelope(SUBTYPES.GEOM2D);
-                } else {
-                    envelope = geomManager.createEnvelope(SUBTYPES.GEOM3D);
-                }
+                // FIXME: De momento forzamos a que todas las geometrías que se
+                // creen sean 3D porque el método getFeatureTypes solo puede
+                // crear los geometryAttributes como 3D
+                int subtypeHeader;
+                    subtypeHeader = Geometry.SUBTYPES.GEOM3D;
 
+                envelope = geomManager.createEnvelope(subtypeHeader);
+
                 FeatureType type = getDefaultType().getNotEditableCopy();
 
                 int counterOfElement = 0;
@@ -752,7 +759,7 @@
 
                     zvalue = 0;
                     try {
-                        int subtype;
+                        int subtypeElement;
                         switch (elemento.stype) {
                         case DGNFileHeader.DGNST_COMPLEX_HEADER:
                             parentElement = (DGNElemComplexHeader) elemento;
@@ -768,11 +775,11 @@
                                 zvalue = p.getZ();
                             } else {
                                 OrientablePrimitive geom = null;
-                                subtype = getGeometrySubType(dgnmultipoint);
+                                subtypeElement = getGeometrySubType(dgnmultipoint);
                                 if (dgnmultipoint.isPolygon()) {
-                                    geom = (OrientablePrimitive) geomManager.create(Geometry.TYPES.SURFACE,subtype);
+                                    geom = (OrientablePrimitive) geomManager.create(Geometry.TYPES.SURFACE,subtypeHeader);
                                 } else {
-                                    geom = (OrientablePrimitive) geomManager.create(Geometry.TYPES.CURVE,subtype);
+                                    geom = (OrientablePrimitive) geomManager.create(Geometry.TYPES.CURVE,subtypeHeader);
                                 }
 
                                 // Si es una curva nos saltamos los dos primeros y los dos ultimos vertices.
@@ -835,21 +842,21 @@
                             elShapeArc.transform(mT);
 
                             OrientablePrimitive geom = null;
-                            subtype = getGeometrySubType(dgnarc);
+                            subtypeElement = getGeometrySubType(dgnarc);
                             if (dgnarc.isSurface()) {
                                 geom = (OrientablePrimitive) geomManager.create(
-                                        Geometry.TYPES.SURFACE, subtype);
+                                        Geometry.TYPES.SURFACE, subtypeHeader);
                             } else {
                                 geom = (OrientablePrimitive) geomManager.create(
-                                        Geometry.TYPES.CURVE, subtype);
+                                        Geometry.TYPES.CURVE, subtypeHeader);
                             }
                             geom.setGeneralPath(elShapeArc);
-                            if ((subtype == Geometry.SUBTYPES.GEOM3D || subtype == Geometry.SUBTYPES.GEOM3DM)
+                            if ((subtypeElement == Geometry.SUBTYPES.GEOM3D || subtypeElement == Geometry.SUBTYPES.GEOM3DM)
                                 && !ignoreZs) {
                                 for (int i = 0; i < geom.getNumVertices(); i++) {
                                     Point originalvertex = geom.getVertex(i);
                                     Point vertex =
-                                        (Point) geomManager.create(Geometry.TYPES.POINT, subtype);
+                                        (Point) geomManager.create(Geometry.TYPES.POINT, subtypeElement);
                                     vertex.setCoordinateAt(0,originalvertex.getX());
                                     vertex.setCoordinateAt(1,originalvertex.getY());
                                     vertex.setCoordinateAt(2, zvalue);
@@ -865,12 +872,16 @@
 
                         case DGNFileHeader.DGNST_TEXT:
                             DGNElemText dgntext = (DGNElemText) elemento;
-                            subtype = getGeometrySubType(dgntext);
-                            Point point = (Point) geomManager.create(TYPES.POINT, subtype);
+                            subtypeElement = getGeometrySubType(dgntext);
+                            Point point = (Point) geomManager.create(TYPES.POINT, subtypeHeader);
                             point.setCoordinateAt(0, dgntext.getPoint().getX());
                             point.setCoordinateAt(1, dgntext.getPoint().getY());
-                            if (subtype == Geometry.SUBTYPES.GEOM3D) {
-                                point.setCoordinateAt(2, dgntext.getPoint().getZ());
+                            if (subtypeHeader == Geometry.SUBTYPES.GEOM3D) {
+                                if(subtypeElement == Geometry.SUBTYPES.GEOM2D){
+                                    point.setCoordinateAt(2, 0);
+                                } else {
+                                    point.setCoordinateAt(2, dgntext.getPoint().getZ());
+                                }
                             }
 
                             data.set(ID_FIELD_HEIGHTTEXT, dgntext.getHeight());
@@ -900,27 +911,22 @@
                     addFeature(data, dgnReader);
                 } // for
 
-                EditableFeatureType featureType = store.getFeatureStore().getDefaultFeatureType().getCopy().getEditable();
+                EditableFeatureType featureType = storeProvider.getFeatureStore().getDefaultFeatureType().getCopy().getEditable();
                 FeatureAttributeDescriptor fad = (FeatureAttributeDescriptor) featureType.get(featureType.getDefaultGeometryAttributeName());
                 featureType.remove(fad.getName());
                 EditableFeatureAttributeDescriptor efad = featureType.add(fad.getName(), fad.getType(), fad.getSize());
                 efad.setDefaultValue(fad.getDefaultValue());
 
                 GeometryType gty = null;
-                int geometrySubtype;
-                if (dgnReader.is3D()) {
-                    geometrySubtype = Geometry.SUBTYPES.GEOM3D;
-                } else {
-                    geometrySubtype = Geometry.SUBTYPES.GEOM2D;
-                }
 
-                gty = geomManager.getGeometryType(fad.getGeomType().getType(),geometrySubtype);
+                gty = geomManager.getGeometryType(fad.getGeomType().getType(),subtypeHeader);
 
                 efad.setGeometryType(gty);
 
                 efad.setPrecision(fad.getPrecision());
                 featureType.setDefaultGeometryAttributeName(fad.getName());
 
+
                 if (xmlbfw != null) {
                     try {
                         xmlbfw.write("</DGN>\n");
