This is an automated email from the ASF dual-hosted git repository.

andy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/jena.git


The following commit(s) were added to refs/heads/main by this push:
     new 1352a6d7a3 GH-3593: Remove SpatialIndexV1
1352a6d7a3 is described below

commit 1352a6d7a33b932392c2f37cbd98fbd3fee2c730
Author: Andy Seaborne <[email protected]>
AuthorDate: Fri Jan 16 11:00:01 2026 +0000

    GH-3593: Remove SpatialIndexV1
---
 .../geosparql/spatial/SpatialIndexStorage.java     | 115 ----
 .../spatial/index/compat/SpatialIndexIo.java       |  34 +-
 .../spatial/index/v1/SpatialIndexAdapterV1.java    |  88 ----
 .../geosparql/spatial/index/v1/SpatialIndexV1.java | 582 ---------------------
 .../spatial/TestSpatialIndexGraphLookupV1.java     |  39 --
 .../spatial/index/v2/SpatialIndexTest.java         |  60 +--
 6 files changed, 25 insertions(+), 893 deletions(-)

diff --git 
a/jena-geosparql/src/main/java/org/apache/jena/geosparql/spatial/SpatialIndexStorage.java
 
b/jena-geosparql/src/main/java/org/apache/jena/geosparql/spatial/SpatialIndexStorage.java
deleted file mode 100644
index 08a3c8a3ff..0000000000
--- 
a/jena-geosparql/src/main/java/org/apache/jena/geosparql/spatial/SpatialIndexStorage.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- *   SPDX-License-Identifier: Apache-2.0
- */
-package org.apache.jena.geosparql.spatial;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import org.apache.jena.geosparql.spatial.index.v1.SpatialIndexV1;
-import org.apache.jena.rdf.model.Resource;
-import org.apache.jena.rdf.model.ResourceFactory;
-import org.locationtech.jts.geom.Envelope;
-
-/**
- * Spatial Index Items in a Serializable form for file reading or writing.
- *
- *
- */
-@Deprecated
-public class SpatialIndexStorage implements Serializable {
-    /* Serializable java class of spatial index v1. Moving this class would 
break Java serialization. */
-    private final String srsURI;
-    private final List<StorageItem> storageItems;
-
-    public SpatialIndexStorage(Collection<SpatialIndexItem> spatialIndexItems, 
String srsURI) {
-
-        this.srsURI = srsURI;
-
-        this.storageItems = new ArrayList<>(spatialIndexItems.size());
-
-        for (SpatialIndexItem spatialIndexItem : spatialIndexItems) {
-            StorageItem storageItem = new 
StorageItem(spatialIndexItem.getEnvelope(), 
spatialIndexItem.getItem().getURI());
-            storageItems.add(storageItem);
-        }
-    }
-
-    public String getSrsURI() {
-        return srsURI;
-    }
-
-    public Collection<SpatialIndexItem> getIndexItems() {
-
-        List<SpatialIndexItem> indexItems = new 
ArrayList<>(storageItems.size());
-
-        for (StorageItem storageItem : storageItems) {
-            SpatialIndexItem indexItem = storageItem.getIndexItem();
-            indexItems.add(indexItem);
-        }
-
-        return indexItems;
-    }
-
-
-    @SuppressWarnings("removal")
-    public SpatialIndexV1 getSpatialIndex() throws SpatialIndexException {
-        return new SpatialIndexV1(getIndexItems(), srsURI);
-    }
-
-    private class StorageItem implements Serializable {
-
-        private final Envelope envelope;
-        private final String uri;
-
-        public StorageItem(Envelope envelope, Resource item) {
-            this.envelope = envelope;
-            this.uri = item.getURI();
-        }
-
-        public StorageItem(Envelope envelope, String uri) {
-            this.envelope = envelope;
-            this.uri = uri;
-        }
-
-        public Envelope getEnvelope() {
-            return envelope;
-        }
-
-        public String getUri() {
-            return uri;
-        }
-
-        public Resource getItem() {
-            return ResourceFactory.createResource(uri);
-        }
-
-        public SpatialIndexItem getIndexItem() {
-            return new SpatialIndexItem(envelope, getItem());
-        }
-
-        @Override
-        public String toString() {
-            return "StorageItem{" + "envelope=" + envelope + ", uri=" + uri + 
'}';
-        }
-
-    }
-}
diff --git 
a/jena-geosparql/src/main/java/org/apache/jena/geosparql/spatial/index/compat/SpatialIndexIo.java
 
b/jena-geosparql/src/main/java/org/apache/jena/geosparql/spatial/index/compat/SpatialIndexIo.java
index a9efffe379..e6d2aa99a6 100644
--- 
a/jena-geosparql/src/main/java/org/apache/jena/geosparql/spatial/index/compat/SpatialIndexIo.java
+++ 
b/jena-geosparql/src/main/java/org/apache/jena/geosparql/spatial/index/compat/SpatialIndexIo.java
@@ -25,45 +25,15 @@ import java.nio.file.Path;
 
 import org.apache.jena.geosparql.spatial.SpatialIndex;
 import org.apache.jena.geosparql.spatial.SpatialIndexException;
-import org.apache.jena.geosparql.spatial.index.v1.SpatialIndexAdapterV1;
 import org.apache.jena.geosparql.spatial.index.v2.SpatialIndexIoKryo;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-@SuppressWarnings("removal")
 public class SpatialIndexIo {
     private static final Logger LOGGER = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
     /** Attempt to load a spatial index from file using all supported formats. 
*/
     public static final SpatialIndex load(Path spatialIndexFile) throws 
SpatialIndexException {
-        return load(spatialIndexFile, false);
-    }
-
-    /**
-     * Attempt to load a spatial index from file using all supported formats.
-     * This method should only be used for testing as it allows suppressing 
warnings when loading legacy index formats.
-     */
-    public static final SpatialIndex load(Path spatialIndexFile, boolean 
suppressLegacyWarnings) throws SpatialIndexException {
-        SpatialIndex result;
-        try {
-            result = SpatialIndexIoKryo.load(spatialIndexFile);
-        } catch (Throwable t1) {
-            if (!suppressLegacyWarnings) {
-                LOGGER.warn("Failed to load spatial index with latest format. 
Trying legacy formats...", t1);
-            }
-            try {
-                org.apache.jena.geosparql.spatial.index.v1.SpatialIndexV1 v1 = 
org.apache.jena.geosparql.spatial.index.v1.SpatialIndexV1.load(spatialIndexFile.toFile());
-                result = new SpatialIndexAdapterV1(v1);
-
-                if (!suppressLegacyWarnings) {
-                    LOGGER.warn("Successfully loaded spatial index with legacy 
format v1. Upgrade advised.");
-                }
-            } catch (Throwable t2) {
-                LOGGER.warn("Failed to load spatial index legacy format.", t2);
-                t1.addSuppressed(new RuntimeException("Failed to load spatial 
index with any format.", t2));
-                throw t1;
-            }
-        }
-        return result;
-    }
+        return SpatialIndexIoKryo.load(spatialIndexFile);
+   }
 }
diff --git 
a/jena-geosparql/src/main/java/org/apache/jena/geosparql/spatial/index/v1/SpatialIndexAdapterV1.java
 
b/jena-geosparql/src/main/java/org/apache/jena/geosparql/spatial/index/v1/SpatialIndexAdapterV1.java
deleted file mode 100644
index eb43195c02..0000000000
--- 
a/jena-geosparql/src/main/java/org/apache/jena/geosparql/spatial/index/v1/SpatialIndexAdapterV1.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- *   SPDX-License-Identifier: Apache-2.0
- */
-package org.apache.jena.geosparql.spatial.index.v1;
-
-import java.io.File;
-import java.nio.file.Path;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Optional;
-import java.util.stream.Collectors;
-
-import org.apache.jena.geosparql.implementation.SRSInfo;
-import org.apache.jena.geosparql.spatial.SpatialIndex;
-import org.apache.jena.graph.Node;
-import org.apache.jena.rdf.model.RDFNode;
-import org.apache.jena.rdf.model.Resource;
-import org.locationtech.jts.geom.Envelope;
-
-/** Adapter class for spatial index v1. */
-@Deprecated(forRemoval=true)
-@SuppressWarnings("removal")
-public class SpatialIndexAdapterV1
-    implements SpatialIndex
-{
-    protected org.apache.jena.geosparql.spatial.index.v1.SpatialIndexV1 v1;
-
-    public 
SpatialIndexAdapterV1(org.apache.jena.geosparql.spatial.index.v1.SpatialIndexV1 
v1) {
-        super();
-        this.v1 = v1;
-    }
-
-    @Override
-    public SRSInfo getSrsInfo() {
-        return v1.getSrsInfo();
-    }
-
-    @Override
-    public boolean isEmpty() {
-        return v1.isEmpty();
-    }
-
-    @Override
-    public long getSize() {
-        return -1;
-    }
-
-    protected Collection<Node> adapt(Collection<? extends RDFNode> resources) {
-        Collection<Node> result = resources.stream()
-            .map(RDFNode::asNode)
-            .collect(Collectors.toCollection(HashSet::new));
-        return result;
-    }
-
-    @Override
-    public Collection<Node> query(Envelope searchEnvelope, Node graphName) {
-        HashSet<Resource> resources = v1.query(searchEnvelope);
-        return adapt(resources);
-    }
-
-    @Override
-    public Path getLocation() {
-        Path result = 
Optional.ofNullable(v1.getLocation()).map(File::toPath).orElse(null);
-        return result;
-    }
-
-    @Override
-    public void setLocation(Path location) {
-        v1.setLocation(location == null ? null : location.toFile());
-    }
-}
diff --git 
a/jena-geosparql/src/main/java/org/apache/jena/geosparql/spatial/index/v1/SpatialIndexV1.java
 
b/jena-geosparql/src/main/java/org/apache/jena/geosparql/spatial/index/v1/SpatialIndexV1.java
deleted file mode 100644
index 5c803a1171..0000000000
--- 
a/jena-geosparql/src/main/java/org/apache/jena/geosparql/spatial/index/v1/SpatialIndexV1.java
+++ /dev/null
@@ -1,582 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- *   SPDX-License-Identifier: Apache-2.0
- */
-package org.apache.jena.geosparql.spatial.index.v1;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.lang.invoke.MethodHandles;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.jena.atlas.RuntimeIOException;
-import org.apache.jena.atlas.io.IOX;
-import org.apache.jena.geosparql.configuration.GeoSPARQLOperations;
-import org.apache.jena.geosparql.implementation.GeometryWrapper;
-import org.apache.jena.geosparql.implementation.SRSInfo;
-import org.apache.jena.geosparql.implementation.registry.SRSRegistry;
-import org.apache.jena.geosparql.implementation.vocabulary.Geo;
-import org.apache.jena.geosparql.implementation.vocabulary.SRS_URI;
-import org.apache.jena.geosparql.implementation.vocabulary.SpatialExtension;
-import org.apache.jena.geosparql.spatial.ConvertLatLon;
-import org.apache.jena.geosparql.spatial.SpatialIndex;
-import org.apache.jena.geosparql.spatial.SpatialIndexConstants;
-import org.apache.jena.geosparql.spatial.SpatialIndexException;
-import org.apache.jena.geosparql.spatial.SpatialIndexItem;
-import org.apache.jena.geosparql.spatial.SpatialIndexStorage;
-import org.apache.jena.geosparql.spatial.index.v2.SpatialIndexLib;
-import org.apache.jena.query.Dataset;
-import org.apache.jena.query.DatasetFactory;
-import org.apache.jena.query.ReadWrite;
-import org.apache.jena.rdf.model.Literal;
-import org.apache.jena.rdf.model.Model;
-import org.apache.jena.rdf.model.NodeIterator;
-import org.apache.jena.rdf.model.RDFNode;
-import org.apache.jena.rdf.model.ResIterator;
-import org.apache.jena.rdf.model.Resource;
-import org.apache.jena.rdf.model.Statement;
-import org.apache.jena.rdf.model.StmtIterator;
-import org.apache.jena.sparql.engine.ExecutionContext;
-import org.apache.jena.sparql.util.Context;
-import org.apache.jena.sparql.util.ModelUtils;
-import org.apache.jena.util.iterator.ExtendedIterator;
-import org.locationtech.jts.geom.Envelope;
-import org.locationtech.jts.index.strtree.STRtree;
-import org.opengis.geometry.MismatchedDimensionException;
-import org.opengis.referencing.operation.TransformException;
-import org.opengis.util.FactoryException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * SpatialIndex for testing bounding box collisions between geometries within a
- * Dataset.<br>
- * Queries must be performed using the same SRS URI as the SpatialIndex.<br>
- * The SpatialIndex is added to the Dataset Context when it is built.<br>
- * QueryRewriteIndex is also stored in the SpatialIndex as its content is
- * Dataset specific.
- */
-@Deprecated(forRemoval=true) /** Superseded by {@link SpatialIndex} and {@link 
org.apache.jena.geosparql.spatial.index.v2.SpatialIndexPerGraph}. */
-public class SpatialIndexV1 {
-
-    private static final Logger LOGGER = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-
-    private transient final SRSInfo srsInfo;
-    private boolean isBuilt;
-    private final STRtree strTree;
-    private static final int MINIMUM_CAPACITY = 2;
-    private File location;
-
-    private SpatialIndexV1() {
-        this.strTree = new STRtree(MINIMUM_CAPACITY);
-        this.isBuilt = true;
-        this.strTree.build();
-        this.srsInfo = SRSRegistry.getSRSInfo(SRS_URI.DEFAULT_WKT_CRS84);
-    }
-
-    /**
-     * Unbuilt Spatial Index with provided capacity.
-     *
-     * @param capacity
-     * @param srsURI
-     */
-    public SpatialIndexV1(int capacity, String srsURI) {
-        int indexCapacity = capacity < MINIMUM_CAPACITY ? MINIMUM_CAPACITY : 
capacity;
-        this.strTree = new STRtree(indexCapacity);
-        this.isBuilt = false;
-        this.srsInfo = SRSRegistry.getSRSInfo(srsURI);
-    }
-
-    /**
-     * Built Spatial Index with provided capacity.
-     *
-     * @param spatialIndexItems
-     * @param srsURI
-     * @throws SpatialIndexException
-     */
-    public SpatialIndexV1(Collection<SpatialIndexItem> spatialIndexItems, 
String srsURI) throws SpatialIndexException {
-        int indexCapacity = spatialIndexItems.size() < MINIMUM_CAPACITY ? 
MINIMUM_CAPACITY : spatialIndexItems.size();
-        this.strTree = new STRtree(indexCapacity);
-        insertItems(spatialIndexItems);
-        this.strTree.build();
-        this.isBuilt = true;
-        this.srsInfo = SRSRegistry.getSRSInfo(srsURI);
-    }
-
-    public File getLocation() {
-        return location;
-    }
-
-    public void setLocation(File location) {
-        this.location = location;
-    }
-
-    /**
-     *
-     * @return Information about the SRS used by the SpatialIndex.
-     */
-    public SRSInfo getSrsInfo() {
-        return srsInfo;
-    }
-
-    /**
-     *
-     * @return True if the SpatialIndex is empty.
-     */
-    public boolean isEmpty() {
-        return strTree.isEmpty();
-    }
-
-    /**
-     *
-     * @return True if the SpatialIndex has been built.
-     */
-    public boolean isBuilt() {
-        return isBuilt;
-    }
-
-    /**
-     * Build the Spatial Index. No more items can be added.
-     */
-    public void build() {
-        if (!isBuilt) {
-            strTree.build();
-            isBuilt = true;
-        }
-    }
-
-    /**
-     * Items to add to an unbuilt Spatial Index.
-     *
-     * @param indexItems
-     * @throws SpatialIndexException
-     */
-    public final void insertItems(Collection<SpatialIndexItem> indexItems) 
throws SpatialIndexException {
-
-        for (SpatialIndexItem indexItem : indexItems) {
-            insertItem(indexItem.getEnvelope(), 
ModelUtils.convertGraphNodeToRDFNode(indexItem.getItem()).asResource());
-        }
-    }
-
-    /**
-     * Item to add to an unbuilt Spatial Index.
-     *
-     * @param envelope
-     * @param item
-     * @throws SpatialIndexException
-     */
-    public final void insertItem(Envelope envelope, Resource item) throws 
SpatialIndexException {
-        if (!isBuilt) {
-            strTree.insert(envelope, item);
-        } else {
-            throw new SpatialIndexException("SpatialIndex has been built and 
cannot have additional items.");
-        }
-    }
-
-    @SuppressWarnings("unchecked")
-    public HashSet<Resource> query(Envelope searchEnvelope) {
-        if (!strTree.isEmpty()) {
-            return new HashSet<>(strTree.query(searchEnvelope));
-        } else {
-            return new HashSet<>();
-        }
-    }
-
-    @Override
-    public String toString() {
-        return "SpatialIndex{" + "srsInfo=" + srsInfo + ", isBuilt=" + isBuilt 
+ ", strTree=" + strTree + '}';
-    }
-
-    /**
-     * Retrieve the SpatialIndex from the Context.
-     *
-     * @param execCxt
-     * @return SpatialIndex contained in the Context.
-     * @throws SpatialIndexException
-     */
-    public static final SpatialIndexV1 retrieve(ExecutionContext execCxt) 
throws SpatialIndexException {
-
-        Context context = execCxt.getContext();
-        SpatialIndexV1 spatialIndex = (SpatialIndexV1) 
context.get(SpatialIndexConstants.symSpatialIndex, null);
-
-        if (spatialIndex == null) {
-            throw new SpatialIndexException("Dataset Context does not contain 
SpatialIndex.");
-        }
-
-        return spatialIndex;
-    }
-
-    /**
-     *
-     * @param execCxt
-     * @return True if a SpatialIndex is defined in the ExecutionContext.
-     */
-    public static final boolean isDefined(ExecutionContext execCxt) {
-        Context context = execCxt.getContext();
-        return context.isDefined(SpatialIndexConstants.symSpatialIndex);
-    }
-
-    /**
-     * Set the SpatialIndex into the Context of the Dataset for later retrieval
-     * and use in spatial functions.
-     *
-     * @param dataset
-     * @param spatialIndex
-     */
-    public static final void setSpatialIndex(Dataset dataset, SpatialIndexV1 
spatialIndex) {
-        Context context = dataset.getContext();
-        @SuppressWarnings("removal")
-        SpatialIndex wrapper = new SpatialIndexAdapterV1(spatialIndex);
-        SpatialIndexLib.setSpatialIndex(context, wrapper);
-    }
-
-    /**
-     * Build Spatial Index from all graphs in Dataset.<br>
-     * Dataset contains SpatialIndex in Context.<br>
-     * Spatial Index written to file.
-     *
-     * @param dataset
-     * @param srsURI
-     * @param spatialIndexFile
-     * @return SpatialIndex constructed.
-     * @throws SpatialIndexException
-     */
-    public static SpatialIndexV1 buildSpatialIndex(Dataset dataset, String 
srsURI, File spatialIndexFile) throws SpatialIndexException {
-
-        SpatialIndexV1 spatialIndex = load(spatialIndexFile);
-        spatialIndex.setLocation(spatialIndexFile);
-
-        if (spatialIndex.isEmpty()) {
-            Collection<SpatialIndexItem> spatialIndexItems = 
findSpatialIndexItems(dataset, srsURI);
-            save(spatialIndexFile, spatialIndexItems, srsURI);
-            spatialIndex = new SpatialIndexV1(spatialIndexItems, srsURI);
-            spatialIndex.build();
-        }
-
-        setSpatialIndex(dataset, spatialIndex);
-        return spatialIndex;
-    }
-
-    /**
-     * Build Spatial Index from all graphs in Dataset.<br>
-     * Dataset contains SpatialIndex in Context.<br>
-     * SRS URI based on most frequent found in Dataset.<br>
-     * Spatial Index written to file.
-     *
-     * @param dataset
-     * @param spatialIndexFile
-     * @return SpatialIndex constructed.
-     * @throws SpatialIndexException
-     */
-    public static SpatialIndexV1 buildSpatialIndex(Dataset dataset, File 
spatialIndexFile) throws SpatialIndexException {
-        String srsURI = GeoSPARQLOperations.findModeSRS(dataset);
-        SpatialIndexV1 spatialIndex = buildSpatialIndex(dataset, srsURI, 
spatialIndexFile);
-        return spatialIndex;
-    }
-
-    /**
-     * Build Spatial Index from all graphs in Dataset.<br>
-     * Dataset contains SpatialIndex in Context.
-     *
-     * @param dataset
-     * @param srsURI
-     * @return SpatialIndex constructed.
-     * @throws SpatialIndexException
-     */
-    public static SpatialIndexV1 buildSpatialIndex(Dataset dataset, String 
srsURI) throws SpatialIndexException {
-        LOGGER.info("Building Spatial Index - Started");
-
-        Collection<SpatialIndexItem> items = findSpatialIndexItems(dataset, 
srsURI);
-        SpatialIndexV1 spatialIndex = new SpatialIndexV1(items, srsURI);
-        spatialIndex.build();
-        setSpatialIndex(dataset, spatialIndex);
-        LOGGER.info("Building Spatial Index - Completed");
-        return spatialIndex;
-    }
-
-    /**
-     * Find Spatial Index Items from all graphs in Dataset.<br>
-     *
-     * @param dataset
-     * @param srsURI
-     * @return SpatialIndexItems found.
-     * @throws SpatialIndexException
-     */
-    public static Collection<SpatialIndexItem> findSpatialIndexItems(Dataset 
dataset, String srsURI) throws SpatialIndexException {
-        //Default Model
-        dataset.begin(ReadWrite.READ);
-        Model defaultModel = dataset.getDefaultModel();
-        Collection<SpatialIndexItem> items = 
getSpatialIndexItems(defaultModel, srsURI);
-
-        //Named Models
-        Iterator<String> graphNames = dataset.listNames();
-        while (graphNames.hasNext()) {
-            String graphName = graphNames.next();
-            Model namedModel = dataset.getNamedModel(graphName);
-            Collection<SpatialIndexItem> graphItems = 
getSpatialIndexItems(namedModel, srsURI);
-            items.addAll(graphItems);
-        }
-
-        dataset.end();
-
-        return items;
-    }
-
-    /**
-     * Build Spatial Index from all graphs in Dataset.<br>
-     * Dataset contains SpatialIndex in Context.<br>
-     * SRS URI based on most frequent found in Dataset.
-     *
-     * @param dataset
-     * @return SpatialIndex constructed.
-     * @throws SpatialIndexException
-     */
-    public static SpatialIndexV1 buildSpatialIndex(Dataset dataset) throws 
SpatialIndexException {
-        String srsURI = GeoSPARQLOperations.findModeSRS(dataset);
-        SpatialIndexV1 spatialIndex = buildSpatialIndex(dataset, srsURI);
-        return spatialIndex;
-    }
-
-    /**
-     * Wrap Model in a Dataset and build SpatialIndex.
-     *
-     * @param model
-     * @param srsURI
-     * @return Dataset with default Model and SpatialIndex in Context.
-     * @throws SpatialIndexException
-     */
-    public static final Dataset wrapModel(Model model, String srsURI) throws 
SpatialIndexException {
-
-        Dataset dataset = DatasetFactory.createTxnMem();
-        dataset.setDefaultModel(model);
-        buildSpatialIndex(dataset, srsURI);
-
-        return dataset;
-    }
-
-    /**
-     * Wrap Model in a Dataset and build SpatialIndex.
-     *
-     * @param model
-     * @return Dataset with default Model and SpatialIndex in Context.
-     * @throws SpatialIndexException
-     */
-    public static final Dataset wrapModel(Model model) throws 
SpatialIndexException {
-        Dataset dataset = DatasetFactory.createTxnMem();
-        dataset.setDefaultModel(model);
-        String srsURI = GeoSPARQLOperations.findModeSRS(dataset);
-        buildSpatialIndex(dataset, srsURI);
-
-        return dataset;
-    }
-
-    /**
-     * Find items from the Model transformed to the SRS URI.
-     *
-     * @param model
-     * @param srsURI
-     * @return Items found in the Model in the SRS URI.
-     * @throws SpatialIndexException
-     */
-    public static final Collection<SpatialIndexItem> 
getSpatialIndexItems(Model model, String srsURI) throws SpatialIndexException {
-
-        List<SpatialIndexItem> items = new ArrayList<>();
-
-        //Only add one set of statements as a converted dataset will duplicate 
the same info.
-        if (model.contains(null, Geo.HAS_GEOMETRY_PROP, (Resource) null)) {
-            LOGGER.info("Feature-hasGeometry-Geometry statements found.");
-            if (model.contains(null, SpatialExtension.GEO_LAT_PROP, (Literal) 
null)) {
-                LOGGER.warn("Lat/Lon Geo predicates also found but will not be 
added to index.");
-            }
-            Collection<SpatialIndexItem> geometryLiteralItems = 
getGeometryLiteralIndexItems(model, srsURI);
-            items.addAll(geometryLiteralItems);
-        } else if (model.contains(null, SpatialExtension.GEO_LAT_PROP, 
(Literal) null)) {
-            LOGGER.info("Geo predicate statements found.");
-            Collection<SpatialIndexItem> geoPredicateItems = 
getGeoPredicateIndexItems(model, srsURI);
-            items.addAll(geoPredicateItems);
-        }
-
-        return items;
-    }
-
-    /**
-     *
-     * @param model
-     * @param srsURI
-     * @return GeometryLiteral items prepared for adding to SpatialIndex.
-     * @throws SpatialIndexException
-     */
-    private static Collection<SpatialIndexItem> 
getGeometryLiteralIndexItems(Model model, String srsURI) throws 
SpatialIndexException {
-        List<SpatialIndexItem> items = new ArrayList<>();
-        StmtIterator stmtIt = model.listStatements(null, 
Geo.HAS_GEOMETRY_PROP, (Resource) null);
-        while (stmtIt.hasNext()) {
-            Statement stmt = stmtIt.nextStatement();
-
-            Resource feature = stmt.getSubject();
-            Resource geometry = stmt.getResource();
-
-            ExtendedIterator<RDFNode> nodeIter = 
model.listObjectsOfProperty(geometry, Geo.HAS_SERIALIZATION_PROP);
-            if (!nodeIter.hasNext()) {
-                NodeIterator wktNodeIter = 
model.listObjectsOfProperty(geometry, Geo.AS_WKT_PROP);
-                NodeIterator gmlNodeIter = 
model.listObjectsOfProperty(geometry, Geo.AS_GML_PROP);
-                nodeIter = wktNodeIter.andThen(gmlNodeIter);
-            }
-
-            while (nodeIter.hasNext()) {
-                Literal geometryLiteral = nodeIter.next().asLiteral();
-                GeometryWrapper geometryWrapper = 
GeometryWrapper.extract(geometryLiteral);
-
-                try {
-                    //Ensure all entries in the target SRS URI.
-                    GeometryWrapper transformedGeometryWrapper = 
geometryWrapper.convertSRS(srsURI);
-
-                    Envelope envelope = 
transformedGeometryWrapper.getEnvelope();
-                    SpatialIndexItem item = new SpatialIndexItem(envelope, 
feature);
-                    items.add(item);
-                } catch (FactoryException | MismatchedDimensionException | 
TransformException ex) {
-                    throw new SpatialIndexException("Transformation Exception: 
" + geometryLiteral + ". " + ex.getMessage());
-                }
-
-            }
-        }
-        return items;
-    }
-
-    /**
-     *
-     * @param model
-     * @param srsURI
-     * @return Geo predicate objects prepared for adding to SpatialIndex.
-     */
-    private static Collection<SpatialIndexItem> 
getGeoPredicateIndexItems(Model model, String srsURI) throws 
SpatialIndexException {
-        List<SpatialIndexItem> items = new ArrayList<>();
-        ResIterator resIt = 
model.listResourcesWithProperty(SpatialExtension.GEO_LAT_PROP);
-
-        while (resIt.hasNext()) {
-            Resource feature = resIt.nextResource();
-
-            Literal lat = 
feature.getRequiredProperty(SpatialExtension.GEO_LAT_PROP).getLiteral();
-            Literal lon = 
feature.getProperty(SpatialExtension.GEO_LON_PROP).getLiteral();
-            if (lon == null) {
-                LOGGER.warn("Geo predicates: latitude found but not longitude. 
" + feature);
-                continue;
-            }
-
-            Literal latLonPoint = ConvertLatLon.toLiteral(lat.getFloat(), 
lon.getFloat());
-            GeometryWrapper geometryWrapper = 
GeometryWrapper.extract(latLonPoint);
-
-            try {
-                //Ensure all entries in the target SRS URI.
-                GeometryWrapper transformedGeometryWrapper = 
geometryWrapper.convertSRS(srsURI);
-
-                Envelope envelope = transformedGeometryWrapper.getEnvelope();
-                SpatialIndexItem item = new SpatialIndexItem(envelope, 
feature);
-                items.add(item);
-            } catch (FactoryException | MismatchedDimensionException | 
TransformException ex) {
-                throw new SpatialIndexException("Transformation Exception: " + 
geometryWrapper.getLexicalForm() + ". " + ex.getMessage());
-            }
-        }
-        return items;
-    }
-
-    /**
-     * Load a SpatialIndex from file.<br>
-     * Index will be built and empty if file does not exist or is null.
-     *
-     * @param spatialIndexFile
-     * @return Built Spatial Index.
-     * @throws SpatialIndexException
-     */
-    public static final SpatialIndexV1 load(File spatialIndexFile) throws 
SpatialIndexException {
-
-        if (spatialIndexFile != null && spatialIndexFile.exists()) {
-            LOGGER.info("Loading Spatial Index - Started: {}", 
spatialIndexFile.getAbsolutePath());
-            //Cannot directly store the SpatialIndex due to Resources not 
being serializable, use SpatialIndexStorage class.
-            try (ObjectInputStream in = new ObjectInputStream(new 
FileInputStream(spatialIndexFile))) {
-                SpatialIndexStorage storage = (SpatialIndexStorage) 
in.readObject();
-
-                SpatialIndexV1 spatialIndex = storage.getSpatialIndex();
-                LOGGER.info("Loading Spatial Index - Completed: {}", 
spatialIndexFile.getAbsolutePath());
-                return spatialIndex;
-            } catch (ClassNotFoundException | IOException ex) {
-                throw new SpatialIndexException("Loading Exception: " + 
ex.getMessage(), ex);
-            }
-        } else {
-            return new SpatialIndexV1();
-        }
-    }
-
-    /**
-     * Save SpatialIndex contents to file.
-     *
-     * @param spatialIndexFileURI
-     * @param spatialIndexItems
-     * @param srsURI
-     * @throws SpatialIndexException
-     */
-    public static final void save(String spatialIndexFileURI, 
Collection<SpatialIndexItem> spatialIndexItems, String srsURI) throws 
SpatialIndexException {
-        save(new File(spatialIndexFileURI), spatialIndexItems, srsURI);
-    }
-
-    /**
-     * Save SpatialIndex contents to file.
-     *
-     * @param spatialIndexFile
-     * @param spatialIndexItems
-     * @param srsURI
-     * @throws SpatialIndexException
-     */
-    public static final void save(File spatialIndexFile, 
Collection<SpatialIndexItem> spatialIndexItems, String srsURI) throws 
SpatialIndexException {
-
-        //Cannot directly store the SpatialIndex due to Resources not being 
serializable, use SpatialIndexStorage class.
-        if (spatialIndexFile != null) {
-            LOGGER.info("Saving Spatial Index - Started: {}", 
spatialIndexFile.getAbsolutePath());
-            SpatialIndexStorage storage = new 
SpatialIndexStorage(spatialIndexItems, srsURI);
-            String filename = spatialIndexFile.getAbsolutePath();
-            Path file = Path.of(filename);
-            Path tmpFile = IOX.uniqueDerivedPath(file, null);
-            try {
-                Files.deleteIfExists(file);
-            } catch (IOException ex) {
-                throw new SpatialIndexException("Failed to delete file: " + 
ex.getMessage());
-            }
-            try {
-                IOX.safeWriteOrCopy(file, tmpFile,
-                                    out->{
-                                        ObjectOutputStream oos = new 
ObjectOutputStream(out);
-                                        oos.writeObject(storage);
-                                        oos.flush();
-                                    });
-            } catch (RuntimeIOException ex) {
-                throw new SpatialIndexException("Save Exception: " + 
ex.getMessage());
-            } finally {
-                LOGGER.info("Saving Spatial Index - Completed: {}", 
spatialIndexFile.getAbsolutePath());
-            }
-        }
-    }
-}
diff --git 
a/jena-geosparql/src/test/java/org/apache/jena/geosparql/spatial/TestSpatialIndexGraphLookupV1.java
 
b/jena-geosparql/src/test/java/org/apache/jena/geosparql/spatial/TestSpatialIndexGraphLookupV1.java
deleted file mode 100644
index 8934cd90a1..0000000000
--- 
a/jena-geosparql/src/test/java/org/apache/jena/geosparql/spatial/TestSpatialIndexGraphLookupV1.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- *   SPDX-License-Identifier: Apache-2.0
- */
-package org.apache.jena.geosparql.spatial;
-
-import org.apache.jena.geosparql.spatial.index.v1.SpatialIndexAdapterV1;
-import org.apache.jena.geosparql.spatial.index.v1.SpatialIndexV1;
-import org.apache.jena.query.DatasetFactory;
-import org.apache.jena.sparql.core.DatasetGraph;
-import org.junit.Ignore;
-
-@SuppressWarnings("removal")
-@Ignore /** These tests reveal issues with the first version of the spatial 
index which did not use per-graph indexes. */
-public class TestSpatialIndexGraphLookupV1
-    extends AbstractSpatialIndexGraphLookpTest
-{
-    @Override
-    protected SpatialIndex buildSpatialIndex(DatasetGraph dsg, String srsUri) 
throws SpatialIndexException {
-        SpatialIndexV1 v1 = 
SpatialIndexV1.buildSpatialIndex(DatasetFactory.wrap(dsg), srsUri);
-        return new SpatialIndexAdapterV1(v1);
-    }
-}
diff --git 
a/jena-geosparql/src/test/java/org/apache/jena/geosparql/spatial/index/v2/SpatialIndexTest.java
 
b/jena-geosparql/src/test/java/org/apache/jena/geosparql/spatial/index/v2/SpatialIndexTest.java
index ac8daf0952..949bdb5942 100644
--- 
a/jena-geosparql/src/test/java/org/apache/jena/geosparql/spatial/index/v2/SpatialIndexTest.java
+++ 
b/jena-geosparql/src/test/java/org/apache/jena/geosparql/spatial/index/v2/SpatialIndexTest.java
@@ -26,50 +26,45 @@ import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.util.Collection;
-import java.util.List;
 import java.util.Map;
-import java.util.Set;
+
+import org.junit.Assert;
+import org.junit.Test;
 
 import org.apache.jena.geosparql.implementation.GeometryWrapperFactory;
 import org.apache.jena.geosparql.implementation.SRSInfo;
 import org.apache.jena.geosparql.implementation.datatype.WKTDatatype;
-import org.apache.jena.geosparql.implementation.vocabulary.SRS_URI;
 import org.apache.jena.geosparql.spatial.SearchEnvelope;
 import org.apache.jena.geosparql.spatial.SpatialIndex;
 import org.apache.jena.geosparql.spatial.SpatialIndexException;
-import org.apache.jena.geosparql.spatial.SpatialIndexItem;
 import org.apache.jena.geosparql.spatial.SpatialIndexTestData;
 import org.apache.jena.geosparql.spatial.index.compat.SpatialIndexIo;
-import org.apache.jena.geosparql.spatial.index.v1.SpatialIndexV1;
 import 
org.apache.jena.geosparql.spatial.index.v2.GeometryGenerator.GeometryType;
 import org.apache.jena.graph.Node;
-import org.apache.jena.query.DatasetFactory;
 import org.apache.jena.sparql.core.DatasetGraph;
 import org.apache.jena.sparql.core.DatasetGraphFactory;
-import org.junit.Assert;
-import org.junit.Test;
 import org.locationtech.jts.geom.Envelope;
 
-@SuppressWarnings("removal")
 public class SpatialIndexTest {
 
-    @Test
-    public void testLegacyLoading() throws IOException, SpatialIndexException {
-        Path file = Files.createTempFile("jena-", ".spatial.index");
-        try {
-            List<SpatialIndexItem> items = SpatialIndexTestData.getTestItems();
-
-            SpatialIndexV1.save(file.toFile(), items, 
SRS_URI.DEFAULT_WKT_CRS84);
-
-            SpatialIndex index = SpatialIndexIo.load(file, true);
-            Envelope envelope = new Envelope(-90, 0, 0, 90);
-            Collection<Node> actual = index.query(envelope, null);
-            Set<Node> expected = 
Set.of(SpatialIndexTestData.LONDON_FEATURE.asNode(), 
SpatialIndexTestData.NEW_YORK_FEATURE.asNode());
-            Assert.assertEquals(expected, actual);
-        } finally {
-            Files.delete(file);
-        }
-    }
+    // Jena5.
+//    @Test
+//    public void testLegacyLoading() throws IOException, 
SpatialIndexException {
+//        Path file = Files.createTempFile("jena-", ".spatial.index");
+//        try {
+//            List<SpatialIndexItem> items = 
SpatialIndexTestData.getTestItems();
+//
+//            SpatialIndexV1.save(file.toFile(), items, 
SRS_URI.DEFAULT_WKT_CRS84);
+//
+//            SpatialIndex index = SpatialIndexIo.load(file, true);
+//            Envelope envelope = new Envelope(-90, 0, 0, 90);
+//            Collection<Node> actual = index.query(envelope, null);
+//            Set<Node> expected = 
Set.of(SpatialIndexTestData.LONDON_FEATURE.asNode(), 
SpatialIndexTestData.NEW_YORK_FEATURE.asNode());
+//            Assert.assertEquals(expected, actual);
+//        } finally {
+//            Files.delete(file);
+//        }
+//    }
 
     @Test
     public void testSerdeSpatialIndex() throws IOException, 
SpatialIndexException {
@@ -82,15 +77,14 @@ public class SpatialIndexTest {
         Collection<Node> res1 = searchEnvelope1.check(index1);
 
         // save to tmp file
-        // File file = new File("/tmp/test-spatial.index"); 
//File.createTempFile( "jena", "spatial.index");
         Path file = Files.createTempFile("jena-", ".spatial-index");
         try {
             SpatialIndexIoKryo.save(file, index1);
 
-            // load from tmp file as new index 2
+            // load from tmp file as a new index
             SpatialIndex index2 = SpatialIndexIo.load(file);
 
-            // query index 2
+            // query index
             SRSInfo srsInfo2 = index2.getSrsInfo();
             SearchEnvelope searchEnvelope2 = 
SearchEnvelope.build(GeometryWrapperFactory.createPolygon(srsInfo2.getDomainEnvelope(),
 WKTDatatype.URI), srsInfo2);
             Collection<Node> res2 = searchEnvelope2.check(index2);
@@ -127,14 +121,6 @@ public class SpatialIndexTest {
             SpatialIndex indexB = SpatialIndexIoKryo.load(file);
             long itemCountB = indexB.query(envelope, null).size();
             Assert.assertEquals(expectedItemCount, itemCountB);
-
-            // Save the index with legacy format and load from file.
-            // File must not exist or the index might/will attempt to load it.
-            Files.delete(file);
-            SpatialIndexV1.buildSpatialIndex(DatasetFactory.wrap(dsg), 
file.toFile());
-            SpatialIndex indexC = SpatialIndexIo.load(file, true);
-            long itemCountC = indexC.query(envelope, null).size();
-            Assert.assertEquals(expectedItemCount, itemCountC);
         } finally {
             Files.deleteIfExists(file);
         }


Reply via email to