2

I'm using Geotools 30-SNAPSHOT and i would like to use ISO Geometry (from opengis package).

I'm using the following code to get ISO geometry related factories:

import org.geotools.geometry.GeometryFactoryFinder;
import org.geotools.referencing.crs.DefaultGeographicCRS;
import org.geotools.util.factory.Hints;
import org.opengis.geometry.PositionFactory;
import org.opengis.geometry.coordinate.GeometryFactory;
import org.opengis.geometry.primitive.PrimitiveFactory;

public class FactoriesSample {

    
    public static void main(String[] args) {
        PositionFactory positionFactory ;
        PrimitiveFactory primitiveFactory;
        GeometryFactory gf;

        Hints hints = new Hints( Hints.CRS, DefaultGeographicCRS.WGS84 );
                
        try {
          positionFactory = GeometryFactoryFinder.getPositionFactory(hints);
        } catch (Exception e) {
          System.out.println("Cannot determine geometry factory: "+e.getMessage());
        }

        try {
          primitiveFactory  = GeometryFactoryFinder.getPrimitiveFactory(hints);
        } catch (Exception e) {
          System.out.println("Cannot determine primitive factory: "+e.getMessage());
        }

        try {
          gf     = GeometryFactoryFinder.getGeometryFactory(hints);
        } catch (Exception e) {
          System.out.println("Cannot determine geometry factory: "+e.getMessage());
        }
    }   
}

My concern is that the execution of the previous code gives:

Cannot determine geometry factory: No factory of type "PositionFactory" has been found.
Cannot determine primitive factory: No factory of type "PrimitiveFactory" has been found.
Cannot determine geometry factory: No factory of type "GeometryFactory" has been found.

It seems that my project has no attached JAR that contains the factories. My maven dependencies are:

<dependency>
    <groupId>org.geotools</groupId>
    <artifactId>gt-epsg-extension</artifactId>
    <version>${geotools.version}</version>
</dependency>

<dependency>
    <groupId>org.geotools</groupId>
    <artifactId>gt-epsg-hsql</artifactId>
    <version>${geotools.version}</version>
</dependency>
            
<dependency>
    <groupId>org.geotools</groupId>
    <artifactId>gt-geotiff</artifactId>
    <version>${geotools.version}</version>
</dependency>
            
<dependency>
    <groupId>org.geotools</groupId>
    <artifactId>gt-image</artifactId>
    <version>${geotools.version}</version>
</dependency>
        
<dependency>
    <groupId>org.geotools</groupId>
    <artifactId>gt-main</artifactId>
    <version>${geotools.version}</version>
</dependency>
        
<dependency>
    <groupId>org.geotools</groupId>
    <artifactId>gt-metadata</artifactId>
    <version>${geotools.version}</version>
</dependency>
        
<dependency>
    <groupId>org.geotools</groupId>
    <artifactId>gt-opengis</artifactId>
    <version>${geotools.version}</version>
</dependency>
        
<dependency>
    <groupId>org.geotools</groupId>
    <artifactId>gt-referencing</artifactId>
    <version>${geotools.version}</version>
</dependency>
        
<dependency>
    <groupId>org.geotools</groupId>
    <artifactId>gt-shapefile</artifactId>
    <version>${geotools.version}</version>
</dependency>
        
<dependency>
    <groupId>org.geotools</groupId>
    <artifactId>gt-swing</artifactId>
    <version>${geotools.version}</version>
</dependency>  
        
<dependency>
    <groupId>org.geotools</groupId>
    <artifactId>gt-transform</artifactId>
    <version>${geotools.version}</version>
</dependency>  
        
<dependency>
    <groupId>org.geotools</groupId>
    <artifactId>gt-xml</artifactId>
    <version>${geotools.version}</version>
</dependency> 
        
<dependency>
    <groupId>org.geotools.xsd</groupId>
    <artifactId>gt-xsd-core</artifactId>
    <version>${geotools.version}</version>
</dependency>  
        
<dependency>
    <groupId>org.geotools.xsd</groupId>
    <artifactId>gt-xsd-gml2</artifactId>
    <version>${geotools.version}</version>
</dependency>
        
<dependency>
    <groupId>org.geotools.xsd</groupId>
    <artifactId>gt-xsd-gml3</artifactId>
    <version>${geotools.version}</version>
</dependency>   

Can you please indicate me which dependencies are missing in order to get the factories or is there is an error within my code ?

Thanks a lot.

1 Answer 1

0

In general the org.opengis.* classes are unused/underused in GeoTools. They were once considered a good idea tm for interoperability but over time it became clear that only GeoTools was using them and the slow standards process was holding back the library's development. So they remain as vestigial classes because no one has the time or money to remove them.

You probably don't want to be using DirectPositions if you can help it, Points or Coordinates are much better supported through out the library. There is a JTS class with helpful conversion methods defined if you need to convert between the two.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.