Index: trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/WrappedSpatialIndex.java
===================================================================
--- trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/WrappedSpatialIndex.java	(revision 0)
+++ trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/WrappedSpatialIndex.java	(revision 43371)
@@ -0,0 +1,256 @@
+/* gvSIG. Desktop Geographic Information System.
+ *
+ * Copyright © 2007-2017 gvSIG Association
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ *
+ * For any additional information, do not hesitate to contact us
+ * at info AT gvsig.com, or visit our website www.gvsig.com.
+ */
+package org.gvsig.fmap.dal.feature.impl;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import org.gvsig.fmap.dal.feature.Feature;
+import org.gvsig.fmap.dal.feature.FeatureReference;
+import org.gvsig.fmap.dal.feature.FeatureStore;
+import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices;
+import org.gvsig.fmap.geom.Geometry;
+import org.gvsig.fmap.geom.SpatialIndex;
+import org.gvsig.fmap.geom.SpatialIndexFactory;
+import org.gvsig.fmap.geom.primitive.Envelope;
+import org.gvsig.tools.exception.BaseException;
+import org.gvsig.tools.service.Manager;
+import org.gvsig.tools.visitor.VisitCanceledException;
+import org.gvsig.tools.visitor.Visitor;
+
+/**
+ * @author fdiaz
+ *
+ */
+public class WrappedSpatialIndex implements SpatialIndex {
+
+    private final SpatialIndex index;
+    private final FeatureStore store;
+
+    protected class Oid2FeatureReferenceVisitor implements Visitor {
+
+        private final Visitor wrapedVisitor;
+
+        public Oid2FeatureReferenceVisitor(Visitor wrapedVisitor) {
+            this.wrapedVisitor = wrapedVisitor;
+        }
+
+        @Override
+        public void visit(Object oid) throws VisitCanceledException, BaseException {
+            DefaultFeatureReference ref = new DefaultFeatureReference(store, oid);
+            wrapedVisitor.visit(ref);
+        }
+
+    }
+
+    protected class Oid2FeatureReferenceIterator implements Iterator {
+
+        private final Iterator wrapedIterator;
+
+        public Oid2FeatureReferenceIterator(Iterator wrapedIterator) {
+            this.wrapedIterator = wrapedIterator;
+        }
+
+        @Override
+        public boolean hasNext() {
+            return this.wrapedIterator.hasNext();
+        }
+
+        @Override
+        public Object next() {
+            Object oid = this.wrapedIterator.next();
+            DefaultFeatureReference ref = new DefaultFeatureReference(store, oid);
+            return ref;
+        }
+
+        @Override
+        public void remove() {
+            this.wrapedIterator.remove();
+        }
+    }
+
+    public WrappedSpatialIndex(SpatialIndex index, FeatureStore store) {
+        this.index = index;
+        this.store = store;
+    }
+
+    @Override
+    public SpatialIndexFactory getFactory() {
+        return this.index.getFactory();
+    }
+
+    @Override
+    public void open() {
+        this.index.open();
+    }
+
+    @Override
+    public void close() {
+        this.index.close();
+    }
+
+    @Override
+    public void query(Envelope envelope, Visitor visitor) {
+        this.index.query(envelope, new Oid2FeatureReferenceVisitor(visitor));
+    }
+
+    @Override
+    public void query(Geometry geom, Visitor visitor) {
+        this.index.query(geom, new Oid2FeatureReferenceVisitor(visitor));
+    }
+
+    @Override
+    public Iterator query(Envelope envelope, long limit) {
+        return new Oid2FeatureReferenceIterator(this.index.query(envelope, limit));
+    }
+
+    @Override
+    public Iterator query(Envelope envelope) {
+        return new Oid2FeatureReferenceIterator(this.index.query(envelope));
+    }
+
+    @Override
+    public Iterator query(Geometry geom, long limit) {
+        return new Oid2FeatureReferenceIterator(this.index.query(geom, limit));
+    }
+
+    @Override
+    public Iterator query(Geometry geom) {
+        return new Oid2FeatureReferenceIterator(this.index.query(geom));
+    }
+
+    @Override
+    public Iterator queryNearest(Envelope envelope, long limit) {
+        return new Oid2FeatureReferenceIterator(this.index.queryNearest(envelope, limit));
+    }
+
+    @Override
+    public Iterator queryNearest(Envelope envelope) {
+        return new Oid2FeatureReferenceIterator(this.index.queryNearest(envelope));
+    }
+
+    @Override
+    public Iterator queryNearest(Geometry geom, long limit) {
+        return new Oid2FeatureReferenceIterator(this.index.queryNearest(geom, limit));
+    }
+
+    @Override
+    public Iterator queryNearest(Geometry geom) {
+        return new Oid2FeatureReferenceIterator(this.index.queryNearest(geom));
+    }
+
+    @Override
+    public Iterator queryAll() {
+        return new Oid2FeatureReferenceIterator(this.index.queryAll());
+    }
+
+    @Override
+    public List queryAsList(Envelope envelope) {
+        return asList( this.query(envelope));
+    }
+
+    @Override
+    public List queryAsList(Geometry geom) {
+        return asList( this.query(geom));
+    }
+
+    @Override
+    public List queryAllAsList() {
+        return asList( this.queryAll());
+    }
+
+    @Override
+    public void insert(Envelope envelope, Object data) {
+        this.index.insert(envelope, getOID(data));
+    }
+
+    @Override
+    public void insert(Geometry geom, Object data) {
+        this.index.insert(geom, getOID(data));
+    }
+
+    @Override
+    public void insert(Geometry geom) {
+        this.index.insert(geom);
+    }
+
+    @Override
+    public boolean remove(Envelope envelope, Object data) {
+        return this.index.remove(envelope, getOID(data));
+    }
+
+    @Override
+    public boolean remove(Geometry geom, Object data) {
+        return this.index.remove(geom, getOID(data));
+    }
+
+    @Override
+    public boolean remove(Geometry geom) {
+        return this.index.remove(geom);
+    }
+
+    @Override
+    public void removeAll() {
+        this.index.removeAll();
+    }
+
+    @Override
+    public long size() {
+        return this.index.size();
+    }
+
+    @Override
+    public void flush() {
+        this.index.flush();
+    }
+
+    @Override
+    public Manager getManager() {
+        return this.index.getManager();
+    }
+
+    protected Object getOID(Object obj) {
+        if( obj == null ) {
+            return null;
+        }
+        if( obj instanceof FeatureReferenceProviderServices ) {
+            return ((FeatureReferenceProviderServices)obj).getOID();
+        }
+        if( obj instanceof Feature ) {
+            FeatureReference f = ((Feature)obj).getReference();
+            return ((FeatureReferenceProviderServices)f).getOID();
+        }
+        if( obj instanceof Number ) {
+            return obj;
+        }
+        throw new IllegalArgumentException("Can't get OID from object of type '"+obj.getClass().getName()+"'.");
+    }
+
+    protected List asList(Iterator it) {
+        List l = new ArrayList();
+        while (it.hasNext()) {
+            l.add(it.next());
+        }
+        return l;
+    }
+}
\ No newline at end of file
Index: trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/DefaultFeatureStore.java
===================================================================
--- trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/DefaultFeatureStore.java	(revision 43370)
+++ trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/DefaultFeatureStore.java	(revision 43371)
@@ -36,8 +36,8 @@
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
+
 import org.apache.commons.io.FilenameUtils;
-
 import org.cresques.cts.IProjection;
 
 import org.gvsig.fmap.dal.DALLocator;
@@ -2587,4 +2587,14 @@
     public Throwable getBreakingsCause() {
             return this.state.getBreakingsCause();
     }
+
+    @Override
+    public SpatialIndex wrapSpatialIndex(SpatialIndex index) {
+//      FeatureStoreProviderFactory factory = (FeatureStoreProviderFactory) this.getProviderFactory();
+//      if( !factory.supportNumericOID() ) {
+//          return null;
+//      }
+      SpatialIndex wrappedIndex = new WrappedSpatialIndex(index, this);
+      return wrappedIndex;
+  }
 }
\ No newline at end of file
Index: trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/feature/FeatureStore.java
===================================================================
--- trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/feature/FeatureStore.java	(revision 43370)
+++ trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/feature/FeatureStore.java	(revision 43371)
@@ -39,6 +39,7 @@
 import org.gvsig.fmap.dal.feature.exception.FeatureIndexException;
 import org.gvsig.fmap.dal.feature.exception.NeedEditingModeException;
 import org.gvsig.fmap.geom.Geometry;
+import org.gvsig.fmap.geom.SpatialIndex;
 import org.gvsig.fmap.geom.primitive.Envelope;
 import org.gvsig.tools.dispose.DisposableIterator;
 import org.gvsig.tools.dynobject.DynObject;
@@ -260,18 +261,18 @@
 
     /**
      * Return a paginated list of Features filtered by the query.
-     * 
+     *
      * The returned List of Features is paginated, and the page size
      * used is "pageSize".
-     * 
+     *
      * @param query to filter the returned feature list
      * @param pageSize the page size of the list
      * @return the list of features
      */
     public List<Feature> getFeatures(FeatureQuery query, int pageSize);
-    
+
     public List<Feature> getFeatures();
-    
+
     /**
      * Returns the feature given its reference.
      *
@@ -498,15 +499,15 @@
         throws DataException;
 
     /**
-     * Creates a new feature of default {@link FeatureType}. 
-     * The new feature should be initialized with the values of the feature 
+     * Creates a new feature of default {@link FeatureType}.
+     * The new feature should be initialized with the values of the feature
      * passed as parameter.
      * Values are inicialiced by name from the feature specified. Error in
      * value assignement are ignoreds.
-     * 
+     *
      * @param defaultValues the values to initialize the new feature.
      * @return the new feature
-     * @throws DataException 
+     * @throws DataException
      */
     public EditableFeature createNewFeature(Feature defaultValues)
         throws DataException;
@@ -850,17 +851,23 @@
      * @return
      */
     public Feature getFeature(DynObject dynobject);
-    
+
     public Iterator iterator();
-    
+
     public ExpressionEvaluator createExpression();
-    
+
     public void createCache(String name, DynObject parameters)
         throws DataException;
 
-    public FeatureCache getCache();     
-    
+    public FeatureCache getCache();
+
     public boolean isBroken();
-	
+
 	public Throwable getBreakingsCause();
+
+    /**
+     * @param index
+     * @return
+     */
+    SpatialIndex wrapSpatialIndex(SpatialIndex index);
 }
Index: trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/test/java/org/gvsig/fmap/dal/feature/DummyFetureStore.java
===================================================================
--- trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/test/java/org/gvsig/fmap/dal/feature/DummyFetureStore.java	(revision 43370)
+++ trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/test/java/org/gvsig/fmap/dal/feature/DummyFetureStore.java	(revision 43371)
@@ -17,6 +17,7 @@
 import org.gvsig.fmap.dal.exception.DataException;
 import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
 import org.gvsig.fmap.dal.feature.exception.NeedEditingModeException;
+import org.gvsig.fmap.geom.SpatialIndex;
 import org.gvsig.fmap.geom.primitive.Envelope;
 import org.gvsig.metadata.exceptions.MetadataException;
 import org.gvsig.timesupport.Interval;
@@ -621,4 +622,9 @@
         return false;
     }
 
+    @Override
+    public SpatialIndex wrapSpatialIndex(SpatialIndex index) {
+        return null;
+    }
+
 }
Index: trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.geometry.app/org.gvsig.geometry.app.jts/src/main/assembly/gvsig-plugin-package.xml
===================================================================
--- trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.geometry.app/org.gvsig.geometry.app.jts/src/main/assembly/gvsig-plugin-package.xml	(revision 43370)
+++ trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.geometry.app/org.gvsig.geometry.app.jts/src/main/assembly/gvsig-plugin-package.xml	(revision 43371)
@@ -59,6 +59,8 @@
         <include>org.gvsig:org.gvsig.fmap.geometry.jts</include>
         <include>org.gvsig:org.gvsig.fmap.geometry.operation.jts</include>
         <include>org.hibernate:hibernate-spatial</include>
+        <include>net.sf:jsi</include>
+        <include>gnu.trove:trove</include>
       </includes>
     </dependencySet>
   </dependencySets>
Index: trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.geometry.app/org.gvsig.geometry.app.jts/pom.xml
===================================================================
--- trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.geometry.app/org.gvsig.geometry.app.jts/pom.xml	(revision 43370)
+++ trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.geometry.app/org.gvsig.geometry.app.jts/pom.xml	(revision 43371)
@@ -77,6 +77,18 @@
       <version>4.0</version>
       <scope>runtime</scope>
     </dependency>
+
+                <dependency>
+                <groupId>net.sf</groupId>
+                <artifactId>jsi</artifactId>
+                <version>unknown</version>
+            </dependency>
+
+            <dependency>
+    <groupId>gnu.trove</groupId>
+    <artifactId>trove</artifactId>
+    <scope>runtime</scope>
+    </dependency>
   </dependencies>
 
   <properties>
Index: trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/assembly/gvsig-plugin-package.xml
===================================================================
--- trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/assembly/gvsig-plugin-package.xml	(revision 43370)
+++ trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/assembly/gvsig-plugin-package.xml	(revision 43371)
@@ -60,8 +60,6 @@
         <include>java3d:vecmath</include>
         <include>joda-time:joda-time</include>
         <include>net.sf:sqljep</include>
-        <include>net.sf:jsi</include>
-        <include>gnu.trove:trove</include>
 
         <include>org.gvsig:org.gvsig.fmap.control</include>
         <include>org.gvsig:org.gvsig.fmap.dal.api</include>
