All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.datanucleus.jdo.spatial.AoSpatialHelper Maven / Gradle / Ivy

There is a newer version: 3.2.4
Show newest version
/**********************************************************************
 Copyright (c) 2007 Roger Blum, Pascal N�esch and others. All rights reserved.
 Licensed 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

 http://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.

 Contributors:
 ...
 **********************************************************************/
package org.datanucleus.jdo.spatial;

import java.io.IOException;

import javax.jdo.PersistenceManager;

import org.datanucleus.api.jdo.JDOPersistenceManagerFactory;

import com.esri.arcgis.geometry.IGeometry;

/**
 * Helper class to read Spatial MetaData from the datastore, specialized for the geometry classes of 
 * the ESRO ArcObjects. The methods assumes that users know what they're doing and will 
 * automatically downcast query results to com.esri.arcgis.geometry.IGeometry.
 */
public class AoSpatialHelper extends SpatialHelper
{
    /**
     * Creates a new AoSpatialHelper instance for the given PMF.
     * 
     * @param pmf The PMF, can't be null or closed.
     */
    public AoSpatialHelper(JDOPersistenceManagerFactory pmf)
    {
        super(pmf);
    }

    /**
     * Returns the srid of the first datastore entry for the given geometry field. 
     * Will return null, if there are no entries or if the geometry 
     * field of the first entry is null. Creates a new 
     * PersistenceManager to execute the query on the datastore.
     *
     * @param pc The PersistenceCapapable class
     * @param fieldName Name of the geometry field
     * @return The srid or null
     */
    public Integer getSridFromDatastoreEntry(Class pc, String fieldName)
    {
        return getSridFromDatastoreEntry(pc, fieldName, pmf.getPersistenceManager());
    }

    /**
     * Returns the srid of the first datastore entry for the given geometry field. 
     * Will return null, if there are no entries or if the geometry 
     * field of the first entry is null.
     *
     * @param pc The PersistenceCapapable class
     * @param fieldName Name of the geometry field
     * @param pm PersistenceManager instance that should be used 
     *        to access the datastore
     * @return The srid or null
     */
    public Integer getSridFromDatastoreEntry(final Class pc, final String fieldName, final PersistenceManager pm)
    {
        checkValid(pc, fieldName);
    
        Integer srid = null;
        IGeometry geom = (IGeometry) readFirstValueForField(pc, fieldName, pm);
        if (geom != null)
        {
            try
            {
                srid = Integer.valueOf(geom.getSpatialReference().getSpatialReferenceImpl());
            }
            catch (IOException e)
            {
                return null;
            }
        }
        
        return srid;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy