Added by jgarnett, last edited by jgarnett on Aug 01, 2007  (view change)

Labels

 
(None)

Factories are classes used to create other objects. This module provides geometry factories allowing you to make a range of spatial objects.

The next section will show how to create specific Geometry objects.

Using GeometryBuilder

There is a GeometryBuilder class to help manage and create factories. This allows you to use only the factory GeoAPI interfaces and not worry about the implementations. The GeometryBuilder is found in the referencing package at org.geotools.geometry.GeometryBuilder. The following example shows how you can use the builder to create and manage factories:

GeometryBuilder builder = new GeometryBuilder(DefaultGeographicCRS.WGS84);
PositionFactory posF = builder.getPositionFactory();
PrimitiveFactory primFF = builder.getPrimitiveFactory();
GeometryFactory geomF = builder.getGeometryFactory();

When you ask for a factory, if the builder has a matching cached factory, it will return that. Otherwise the builder will create and return a new factory, caching it for later use. You can update the builder's CRS, like in the following example, and get a new factory using the new CRS.

builder.setCoordianteReferenceSystem(DefaultGeographicCRS.WGS84_3D);
PositionFactory posF3D = builder.getPositionFactory();

Assemble the Factories by Hand

The following example shows how to create some factories directly from their implementations:

PositionFactory posF = new PositionFactoryImpl(DefaultGeographicCRS.WGS84, new PrecisionModel());
PrimitiveFactory primF = new PrimitiveFactoryImpl(DefaultGeographicCRS.WGS84, posF);

Using a Container

Another way you could manage factories is directly through the implementations with a container. For more information on using something like a PicoContainer to maintain factory implementations, click here.