Hey,
You have the right idea. You use JTS classes to make the geometry
(through coordinates) and then the Geotools classes to make a CRS and
then you put them together to make a Feature.
I'm working on the tutorials you will want but don't have them yet. I'll
attach three pieces I have.
(1) mucks around with jts geometries
(2) makes a feature *without* a CRS
(3) makes a feature with a CRS
you should be able to sort through and figure things out. If not, you'll
have to wait for my tutorials.
cheers,
adrian
On Tue, 2006-07-11 at 11:50 -0400, Natarajan, Senthil wrote:
> Hi Adrian,
> Thanks for the info and I appreciate.
>
> Here is the more detail about the data. You are right those are UTM
> Projected points.
> UTM Grid Zone: 10S
> "UTM-X, m:" 560531
> "UTM-Y, m:" 4181786
> Datum: 1927 NAD
>
> What I want to do is, just to start with, I need to create a map for
> these points.
> X,Y
> 566469,4181502
> 567309,4177908
> 567306,4178221
> 563567,4182488
> 563601,4182221
> 560531,4181786
>
> I created a map manually using ArcGIS, by just opening the above points
> saved in a .txt file. Please find the attached map file.
>
> I just want to do produce the same map programmatically by using some
> open source GIS API.
> Is it possible to do this by using JTS?
>
> Do I need to create some coordinate points like this........
> Coordinate ptc = new Coordinate(14.0d,14.0d);
>
> // Create an array and add the coordinates for a line
> Coordinate[] lsc = new Coordinate[7];
> lsc[0] = new Coordinate(5.0d,5.0d);
> lsc[1] = new Coordinate(6.0d,5.0d);
> lsc[2] = new Coordinate(6.0d,6.0d);
> lsc[3] = new Coordinate(7.0d,6.0d);
> lsc[4] = new Coordinate(7.0d,7.0d);
> lsc[5] = new Coordinate(8.0d,7.0d);
> lsc[6] = new Coordinate(8.0d,8.0d);
>
> I am new to this, it will be great if you could point out some classes
> which does this (i.e) by taking the above UTM coordinate points and
> produce the map like the one I attached.
>
> Thanks,
> Senthil
>
>
>
>
> -----Original Message-----
> From: Adrian Custer [mailto:[EMAIL PROTECTED]
> Sent: Monday, July 10, 2006 7:36 AM
> To: Natarajan, Senthil
> Cc: Geotools users list
> Subject: Re: [Geotools-gt2-users] Generating Map for set of Lat/Long
> Points
>
> Hello,
>
> This is a great first question. I wish we had a tutorial just to answer
> this question and I hope to build one eventually. For now you are going
> to have to work your way through some things on your own.
>
> First, your question is actually incomplete. We could easily generate a
> data set with a point at each of those coordinates, as I will explain
> below. However, if you then expect to match these coordinates to other
> geographic data, you have to have slightly more information, namely the
> projection system you are using. Your data do not seem to be longitudes
> and latitudes but some other projected data; you will therefore need to
> find out what projection they are using.
>
> If all you want to do is create a file of geometric points at those
> coordinates, then you are essentially going to be using the JTS library
> since this is what Geotools uses. You could look on the JTS web site or
> you could read the current documentation prototype at:
> http://docs.codehaus.org/display/GEOTDOC/Programmers+Manual+Prototype
> and checkout the tutorial file
> http://docs.codehaus.org/download/attachments/50776/GnuGIS_Geotools_Tuto
> rial000010_Geometry010_Creation.java?version=1
>
> Note these are both prototypes, in early stages, and so are less elegant
> than they could be but they should get you started. However, because you
> are not using any projection information,
> THIS WILL NOT GIVE YOU POINTS THAT YOU CAN MATCH TO OTHER DATA.
> You have been warned. To do that you will need to build projection data
> and use both your geometry and the projection info to build a geotools
> feature. I'm hoping to write a tutorial about this shortly. Look around
> at the web site for more info.
>
> It would be nice to have a helper function in Geotools to do this simple
> operation and perhaps we can add that eventually.
>
> Good luck,
>
> sincerely,
> adrian custer
>
>
> On Sun, 2006-07-09 at 19:13 -0400, Natarajan, Senthil wrote:
> > Hi,
> >
> > I was wondering is it possible to generate a Map using GeoTools API
> > for a set of Lat/Long points.
> >
> > Basically I need to generate a Map for these Locations.
> >
> > X, Y
> >
> > 566469,4181502
> >
> > 567309,4177908
> >
> > 567306,4178221
> >
> > 563567,4182488
> >
> > 563601,4182221
> >
> > 560531,4181786
> >
> >
> >
> > If it is possible could you point out some example code how to
> > generate the Map. If it is not possible could you please suggest some
> > open source Java API which does this.
> >
> >
> >
> > Thanks,
> >
> > Senthil
> >
> >
> >
> ------------------------------------------------------------------------
> -
> > Using Tomcat but need to do more? Need to support web services,
> security?
> > Get stuff done quickly with pre-integrated technology to make your job
> easier
> > Download IBM WebSphere Application Server v.1.0.1 based on Apache
> Geronimo
> >
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> > _______________________________________________
> > Geotools-gt2-users mailing list
> > [email protected]
> > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>
// WARNING WARNING WARNING
// The brace below is designed to break this code. This is a prototype, in
// the wrong namespace, with the wrong name, wrong license. This tutorial is
// not done yet so this brace breaks the class totally. If you have found this
// code indirectly, you are warned...
{ a brace and some text to totally break this file.
/*
* The gnuGIS tutorial series: Introduction to Geotools.
*
* (c) 2005 Adrian Custer, The GnuGIS Project.
*
* Licensed under the GPL, version 2.
*/
package org.geotools.community.acuster.tutorials;
// JTS imports
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.LineString;
import com.vividsolutions.jts.geom.LinearRing;
import com.vividsolutions.jts.geom.Point;
import com.vividsolutions.jts.geom.Polygon;
/**
* This is
*
* GnuGIS_Geotools_Tutorial000010_Geometry010_Creation.java
*
* a class to examine the Geometric model of the GeoTools code base.
*
* This tutorial was written in April 2006 against the Geotools 2.2RC2 release.
* It has not yet been updated.
*
*
* The Geotools Programmers' Manual:
* --------------------------------
*
* This tutorial is written as part of the Geotools Programmers' Manual which
* will be available on the Geotools web site. The tutorial and manual aim to
* get new programmers started in using the Geotools library. Programmers who
* wish to extend the library should look a the Developpers' Guide instead.
*
* The Geotools Geometric Model:
* ----------------------------
*
* This tutorial introduces the Geometric Model used by Geotools to describe the
* spatial definition of the 'Features' in the GIS.
*
*
* The tutorial starts from scratch:
* --------------------------------
* In this tutorial, we start by creating coordinates out of Java doubles. Then
* we asemble these coordinates into arrays, and use those to make Geotools
* Geometry elements.
*
* In another tutorial we can see how to avoid this pain using Input and Output
* to standard file formats, to databases, and to web servers.
*
*
* The tutorial then uses Well Known Text (WKT):
* --------------------------------------------
*
*
*
* Tutorial Code Structure:
* -----------------------
*
* Note the tutorial does not use Java structure but only a single long
* method. Real code will obviously create Java structure around these pieces.
* Here, for reading simplicity, the code follows the sequential order.
*
*
*
* Material for this tutorial was taken from:
* http://www.geotools.org/CreateAGeometry
* retrived on 24 Sept 2005
*
* @author Adrian Custer, (c) assigned to the Geotools Project Management Committee.
* @version 0.0.1 April 2006
*
*/
public class GnuGIS_Geotools_Tutorial000010_Geometry010_Creation {
public GnuGIS_Geotools_Tutorial000010_Geometry010_Creation(){
}
/**
* @param args
*/
public static void main(String[] args) {
System.out.println("Start of the output for the tutorial: Geometry010_Creation.\n");
////////////////////////////////////
// PART I: Creating Geometry objects
// Geotools uses the JTS library for its basic geometric operations so
// this early code all uses com.vividsolutions.jts.geom.*
// For a tutorial on the JTS library, see TODO: add the link.
// Create a coordinate for a point
Coordinate ptc = new Coordinate(14.0d,14.0d);
// Create an array and add the coordinates for a line
Coordinate[] lsc = new Coordinate[7];
lsc[0] = new Coordinate(5.0d,5.0d);
lsc[1] = new Coordinate(6.0d,5.0d);
lsc[2] = new Coordinate(6.0d,6.0d);
lsc[3] = new Coordinate(7.0d,6.0d);
lsc[4] = new Coordinate(7.0d,7.0d);
lsc[5] = new Coordinate(8.0d,7.0d);
lsc[6] = new Coordinate(8.0d,8.0d);
// Create an array and add the coordinates for a polygon
// Note that the last coordinate is the same as the first
Coordinate[] pgc = new Coordinate[10];
pgc[0] = new Coordinate(7,7);
pgc[1] = new Coordinate(6,9);
pgc[2] = new Coordinate(6,11);
pgc[3] = new Coordinate(7,12);
pgc[4] = new Coordinate(9,11);
pgc[5] = new Coordinate(11,12);
pgc[6] = new Coordinate(13,11);
pgc[7] = new Coordinate(13,9);
pgc[8] = new Coordinate(11,7);
pgc[9] = new Coordinate(7,7);
// Create a com.vividsolutions.jts.geom.GeometryFactory
//
// Geotools uses the idea of factories a lot. It's known as a 'pattern,'
// a common setup that gives a particular kind of flexibility. The idea
// is: you make the factory, change the settings of the factory, and
// then make a new object based on those settings. Factories make it
// easy to create lots of objects with similar settings.
//
GeometryFactory geomFac = new GeometryFactory();
// TODO: HOW? "Here if we wanted to, we could tweak the factory"
// Use the factory to make the jts geometries
// This fatory provides different public methods to construct different
// geometry types.
Point ptG = geomFac.createPoint(ptc);
LineString lnG = geomFac.createLineString(lsc);
LinearRing rgG = geomFac.createLinearRing(pgc);
Polygon pgG = geomFac.createPolygon(rgG,null);
// TODO: add some query stuff.
// Just to see how far we have gotten
System.out.println("The point is: "+ ptG);
System.out.println("The lineString is: "+ lnG);
System.out.println("The linear ring is: "+ rgG);
System.out.println("The polygon is: "+ pgG);
// JTS is cool in printing the geometry objects as Well Known Text (WKT)
System.out.println("\nEnd of the tutorial output.");
}
}
/*
* The gnuGIS tutorial series: Introduction to Geotools.
*
* (c) 2005 Adrian Custer, The GnuGIS Project.
*
* Licensed under the GPL, version 2.
*/
package org.geotools.community.acuster.tutorials;
// The JTS system provides the fundamental geometry for Geotools.
import org.geotools.factory.FactoryConfigurationError;
import org.geotools.feature.AttributeType;
import org.geotools.feature.AttributeTypeFactory;
import org.geotools.feature.Feature;
import org.geotools.feature.FeatureType;
import org.geotools.feature.FeatureTypeBuilder;
import org.geotools.feature.FeatureTypeFactory;
import org.geotools.feature.GeometryAttributeType;
import org.geotools.feature.IllegalAttributeException;
import org.geotools.feature.SchemaException;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.LineString;
import com.vividsolutions.jts.geom.LinearRing;
import com.vividsolutions.jts.geom.Point;
import com.vividsolutions.jts.geom.Polygon;
/**
* This is
*
* GnuGIS_Geotools_Tutorial000100_CreateAFeature.java
*
* a class to examine the basics of the GeoTools code base.
*
* This tutorial was written in September 2005 against the Geotools 2.1 binary
* distribution. It has not yet been updated.
*
* Note the tutorial does not use Java structure but only a single long main
* method. Real code will obviously create Java structure around these pieces.
* Here, for simplicity, the code follows the order necessary to proceed.
*
* The tutorial starts from scratch:
* --------------------------------
* In this tutorial, we start by creating coordinates out of Java doubles. Then
* we asemble these coordinates into arrays, and use those to make Geotools
* Geometry elements.
*
* In another tutorial we can see how to avoid this pain using Input and Output
* to standard file formats, to databases, and to web servers.
*
*
* The tutorial then assembles a "Feature":
* ---------------------------------------
* "Features" are the central object type in Geotools, and indeed in the
* OpenGIS spec itself.
*
* Geotools Feature objects hold (among other stuff):
* -id a Java String
* -schema a Geotools FeatureType
* -attributes a Java array of Objects, of which the first is the geometry
*
* The newest way to create Feature instances is using a method from the
* gt2-experiment.jar in the org.geotools.feature namespace i.e.
* org.geotools.feature.FeatureFactory2. Since this is also the cleanest
* approach this is the approach used here.
*
* So we will use the geometry element created earlier. We also need to build
* the FeatureType used for the schema.
*
* Geotools FeatureType objects hold (among other stuff):
* -name a Java String
* -namespace a Java URI
* -types a Java array of AttributeType objects, the first of which
* describes the geometry
*
*
* Material for this tutorial was taken from:
* http://www.geotools.org/CreateAGeometry
* retrived on 24 Sept 2005
* http://www.geotools.org/How+to+create+a+simple+FeatureCollection+from+Scratch
* retrived on 24 Sept 2005
*
* @author Adrian Custer
* @version 0.0.1 September 2005
*
*/
public class GnuGIS_Geotools_Tutorial000100_CreateAFeature {
public GnuGIS_Geotools_Tutorial000100_CreateAFeature(){
}
/**
* @param args
*/
public static void main(String[] args) {
System.out.println("Start of the output for the tutorial: CreateAFeature.\n");
////////////////////////////////////
// PART I: Creating Geometry objects
// Geotools uses the JTS library for its basic geometric operations so
// this early code all uses com.vividsolutions.jts.geom.*
// For a tutorial on the JTS library, see TODO: add the link.
// Create a coordinate for a point
Coordinate ptc = new Coordinate(14.0d,14.0d);
// Create an array and add the coordinates for a line
Coordinate[] lsc = new Coordinate[7];
lsc[0] = new Coordinate(5.0d,5.0d);
lsc[1] = new Coordinate(6.0d,5.0d);
lsc[2] = new Coordinate(6.0d,6.0d);
lsc[3] = new Coordinate(7.0d,6.0d);
lsc[4] = new Coordinate(7.0d,7.0d);
lsc[5] = new Coordinate(8.0d,7.0d);
lsc[6] = new Coordinate(8.0d,8.0d);
// Create an array and add the coordinates for a polygon
// Note that the last coordinate is the same as the first
Coordinate[] pgc = new Coordinate[10];
pgc[0] = new Coordinate(7,7);
pgc[1] = new Coordinate(6,9);
pgc[2] = new Coordinate(6,11);
pgc[3] = new Coordinate(7,12);
pgc[4] = new Coordinate(9,11);
pgc[5] = new Coordinate(11,12);
pgc[6] = new Coordinate(13,11);
pgc[7] = new Coordinate(13,9);
pgc[8] = new Coordinate(11,7);
pgc[9] = new Coordinate(7,7);
// Create a com.vividsolutions.jts.geom.GeometryFactory
//
// Geotools uses the idea of factories a lot. It's known as a 'pattern,'
// a common setup that gives a particular kind of flexibility. The idea
// is: you make the factory, change the settings of the factory, and
// then make a new object based on those settings. Factories make it
// easy to create lots of objects with similar settings.
//
GeometryFactory geomFac = new GeometryFactory();
// TODO: HOW? "Here if we wanted to, we could tweak the factory"
// Use the factory to make the jts geometries
// This fatory provides different public methods to construct different
// geometry types.
Point ptG = geomFac.createPoint(ptc);
LineString lnG = geomFac.createLineString(lsc);
LinearRing rgG = geomFac.createLinearRing(pgc);
Polygon pgG = geomFac.createPolygon(rgG,null);
// TODO: add some query stuff.
// Just to see how far we have gotten
System.out.println("The polygon is: "+ pgG);
// JTS is cool in printing the geometry objects as Well Known Text (WKT)
// We could play around with JTS objects. The library has a lot of
// functionality but that's the subject of another tutorial.
///////////////////////////////////////
// PART II: Creating the AttributeTypes
// First we create the AttributeTypes we will need, again with a factory
// Create an AttributeTypeFactory
//AttributeTypeFactory atf = AttributeTypeFactory.newInstance();
// Use the factory to make the GeometryAttributes for each Geometry
// This factory works differently---it provides a single static method
// which returns different types based on the parameter list.
GeometryAttributeType ptGA =
(GeometryAttributeType)AttributeTypeFactory.newAttributeType("the_geom", Point.class);
GeometryAttributeType lnGA =
(GeometryAttributeType)AttributeTypeFactory.newAttributeType("the_geom", LineString.class);
GeometryAttributeType rgGA =
(GeometryAttributeType)AttributeTypeFactory.newAttributeType("the_geom", LinearRing.class);
GeometryAttributeType pgGA =
(GeometryAttributeType)AttributeTypeFactory.newAttributeType("the_geom", Polygon.class);
// Create the other attributes for the features
// Attributes we will attach to the Point Geometry: the city name and
// its population---these are, of course, completely invented
AttributeType cityAT =
AttributeTypeFactory.newAttributeType("CITYNAME", String.class, true, 48, null);
AttributeType popAT =
AttributeTypeFactory.newAttributeType("CITYPOP", Double.class, true, 48, null);
// Attributes for the Line Geometry: the river's name
AttributeType riverAT =
AttributeTypeFactory.newAttributeType("RIVERNAME", String.class, true, 48, null);
// No Attributes for the LinearRing
// Attributes for the polygon: a name and a max elevation
AttributeType mxelAT =
AttributeTypeFactory.newAttributeType("MAXELEVATION", Double.class, true, 48, null);
AttributeType islandAT =
AttributeTypeFactory.newAttributeType("ISLANDNAME", String.class, true, 48, null);
//////////////////////////////////
// PART III: Make the FeatureTypes
// Now we the make FeatureTypes for the different features.
//
// There are two approaches, both based on deprecated methods, to create
// the Feature Type.
//
// The point is created through use of the FeatureTypeFactory directly.
// This approach appears to be the older one and so is not used for the
// other geometries. This approach requires first putting the
// AttributeTypes into an array, then using that array to configure a
// factory to give a FeatureType.
//
// The linestring, linearring, and polygon are build using the
// FeatureTypeBuilder. This requires creating a builder, setting up its
// parameters, and then instantiating the FeatureType.
//
// HACK WARNING: Both of these approaches use deprecated methods
// The point FeatureType
// First we put the AttributeTypes into an array.
// Note the GeometricAttributeType has to be first.
AttributeType[] ptATs = new AttributeType[3];
ptATs[0] = ptGA;
ptATs[1] = cityAT;
ptATs[2] = popAT;
// Next we create the FeatureType proper using the older approach which
// creates a FeatureType through a FeatureTypeFactory
FeatureType ptFT = null;
try{
ptFT = FeatureTypeFactory.newFeatureType(ptATs, "pointfeature");
} catch (Exception e){
System.out.println("An exception occurred\n"+e);
}
// To see what we have got:
System.out.println("Point feature type name is: "+ ptFT.getTypeName() );
System.out.println("Point feature type is: "+ ptFT);
//The line FeatureType
// Create a FeatureTypeBuilder
//
// We can't construct FeatureTypeBuilder directly because it's
// abstract. In this case we call a static method of the
// FeatureTypeFactory class.
//
// The newInstance method needs the string value of the FeatureTypes
// these can be obtained using a previous FeatureType by calling its
// .getTypeName() method. For a new FeatureType however, I'm not sure.
// It's not arbitrary since the compiler balks at "bogus"
// TODO: solve the origin of these strings
//
FeatureTypeBuilder lnFTB = null;
try{
lnFTB = FeatureTypeFactory.newInstance("linefeature");
} catch (FactoryConfigurationError fcErr){
System.out.println("A FactoryConfigurationError occured "+ fcErr);
}
// Configure the builder with values
// First give it a name
lnFTB.setName("CityType");
// Then a namespace
//ftbld.setNamespace(("org.gnuGIS.geotools.FeatureTypeNames").getURI());
// TODO: figure out how to generate the URI for the 3 geometries
// Then add the AttributeTypes, geometry first.
lnFTB.addType(lnGA);
lnFTB.addType(riverAT);
// Finally instantiate the feature type.
FeatureType lnFT = null;
try{
lnFT = lnFTB.getFeatureType();
} catch (SchemaException schmE){
System.out.println("AN EXCEPTION OCCURRED"+ schmE);
}
//The linearRing FeatureType
// Create a FeatureTypeBuilder
FeatureTypeBuilder rgFTB = null;
try{
rgFTB = FeatureTypeFactory.newInstance("linearringfeature");
} catch (FactoryConfigurationError fcErr){
System.out.println("A FactoryConfigurationError occured "+ fcErr);
}
// Configure the builder with values
// First give it a name
rgFTB.setName("RiverType");
// Then a namespace
//rgFTB.setNamespace(("org.gnuGIS.geotools.FeatureTypeNames").getURI());
// TODO: figure out how to generate the URI for the 3 geometries
// Then add the AttributeTypes, geometry first.
rgFTB.addType(rgGA);
// Finally instantiate the feature type.
FeatureType rgFT = null;
try{
rgFT = rgFTB.getFeatureType();
} catch (SchemaException schmE){
System.out.println("AN EXCEPTION OCCURRED"+ schmE);
}
//The Polygon FeatureType
// Create a FeatureTypeBuilder
FeatureTypeBuilder pgFTB = null;
try{
pgFTB = FeatureTypeFactory.newInstance("linearringfeature");
} catch (FactoryConfigurationError fcErr){
System.out.println("A FactoryConfigurationError occured "+ fcErr);
}
// Configure the builder with values
// First give it a name
pgFTB.setName("IslandType");
// Then a namespace
//rgFTB.setNamespace(("org.gnuGIS.geotools.FeatureTypeNames").getURI());
// TODO: figure out how to generate the URI for the 3 geometries
// Then add the AttributeTypes, geometry first.
pgFTB.addType(pgGA);
pgFTB.addType(mxelAT);
pgFTB.addType(islandAT);
// Finally instantiate the feature type.
FeatureType pgFT = null;
try{
pgFT = pgFTB.getFeatureType();
} catch (SchemaException schmE){
System.out.println("AN EXCEPTION OCCURRED"+ schmE);
}
//////////////////////////////////////////////////////
// PART IV: put the pieces together in an Object array.
// The point object array
Object [] ptElems = { ptG, "Hometown", new Double(200000d)};
Object [] lnElems = { lnG, "The big fat greasy limpopo"};
Object [] rgElems = { rgG};
Object [] pgElems = { pgG, new Double(1654.0d),"Green Island"};
//////////////////////////////////////////////////////////
// PART V: Finally, let's make the Features and go to bed.
// The point feature
// HACK WARNING: The only method I could find to actually make the
// feature itself is the deprecated method of the FeatureType which
// is an absurd place to do things.
Feature ptF = null;
try {
ptF = ptFT.create(ptElems);
} catch (IllegalAttributeException iattrE){
System.out.println("An exception occurred on Feature creation " + iattrE);
}
// 1) The Feature interface provides no way to create new features
// thanks to SUN's design
// 2) The DefaultFeature class provides only protected constructors and
// no other methods to create a feature.
// 3) The deprecated methods FeatureType.create* suggest using feature
// factories:
// * FeatureFactory is an interface with deprecated methods and no
// implementation.
// * FeatureFactory2 is only implemented by FeatureFactoryImpl which
// would have been the elegant approach but is currently set to
// return null, which is less than interesting
// FOR THE FUTURE:
//FeatureFactoryImpl ff = new FeatureFactoryImpl();
//Feature ptF = ff.create(ptT,ptElems);
// The line feature
Feature lnF = null;
try {
lnF = lnFT.create(lnElems);
} catch (IllegalAttributeException iattrE){
System.out.println("An exception occurred on line Feature creation " + iattrE);
}
// The linearring feature
Feature rgF = null;
try {
rgF = rgFT.create(rgElems);
} catch (IllegalAttributeException iattrE){
System.out.println("An exception occurred on linearring Feature creation " + iattrE);
}
// The polygon feature
Feature pgF = null;
try {
pgF = pgFT.create(pgElems);
} catch (IllegalAttributeException iattrE){
System.out.println("An exception occurred on polygon Feature creation " + iattrE);
}
// To see that we got there.
System.out.println("The point Feature is: " + ptF);
System.out.println("The line Feature is: " + lnF);
System.out.println("The linearRing Feature is: " + rgF);
System.out.println("The polygon Feature is: " + pgF);
System.out.println("\nEnd of the tutorial output.");
}
}
// This code is taken from a uDig project so it's not just Geotools.
// Some of these are relevant, others arn't i'm too lazy to sort them out.
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import org.geotools.data.FeatureReader;
import org.geotools.data.FeatureSource;
import org.geotools.data.FeatureStore;
import org.geotools.feature.AttributeType;
import org.geotools.feature.AttributeTypeFactory;
import org.geotools.feature.Feature;
import org.geotools.feature.FeatureCollection;
import org.geotools.feature.FeatureType;
import org.geotools.feature.FeatureTypeBuilder;
import org.geotools.feature.GeometryAttributeType;
import org.geotools.geometry.jts.JTS;
import org.geotools.referencing.CRS;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.operation.MathTransform;
import org.osgi.framework.Bundle;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.LineString;
import com.vividsolutions.jts.geom.MultiLineString;
import com.vividsolutions.jts.geom.MultiPoint;
import com.vividsolutions.jts.geom.MultiPolygon;
import com.vividsolutions.jts.geom.Polygon;
...
Assume these exist:
Geometry z
CoordinateReferenceSystem targetCoordRefSys
...
*********************************************************************************************
////// STEP 4: Make a feature from the geometries
//////// 4.1: Make the FeatureType using a factory
////////// 4.1.1: Make the GeometryAttributeType
GeometryAttributeType myGT = null;
AttributeType myGeomAT = null;
// TODO: ASK how do we make this more robust to changes in geometry?
Class c = Class.forName("com.vividsolutions.jts.geom."+
z.getGeometryType());
try {
myGeomAT = AttributeTypeFactory.newAttributeType("the_geom",
c, true, 1, null,targetCoordRefSys);
} catch (Exception e){
System.out.println("The exception is: "+ e.getMessage());
}
// A less elegant approach, robust to change of package but doesn't
// pick up new types of geometry. Which is better?
// try {
// if ("Point" == z.getGeometryType()){
// myGeomAT =
AttributeTypeFactory.newAttributeType("the_geom",
// Point.class, true, 1,
null,targetCoordRefSys);
// } else if ("MultiPoint" == z.getGeometryType()){
// myGeomAT =
AttributeTypeFactory.newAttributeType("the_geom",
// MultiPoint.class, true, 1,
null,targetCoordRefSys);
// } else if ("LineString" == z.getGeometryType()){
// myGeomAT =
AttributeTypeFactory.newAttributeType("the_geom",
// LineString.class, true, 1,
null,targetCoordRefSys);
// } else if ("MultiLineString" == z.getGeometryType()){
// myGeomAT =
AttributeTypeFactory.newAttributeType("the_geom",
// MultiLineString.class, true, 1,
null,targetCoordRefSys);
// } else if ("Polygon" == z.getGeometryType()){
// myGeomAT =
AttributeTypeFactory.newAttributeType("the_geom",
// Polygon.class, true, 1,
null,targetCoordRefSys);
// } else if ("MultiPolygon" == z.getGeometryType()){
// myGeomAT =
AttributeTypeFactory.newAttributeType("the_geom",
// MultiPolygon.class, true, 1,
null,targetCoordRefSys);
// }
// } catch (Exception e){
// System.out.println("The exception is: "+ e.getMessage());
// }
if (myGeomAT instanceof GeometryAttributeType){
myGT = (GeometryAttributeType) myGeomAT;
}
FeatureTypeBuilder myFTBuilder = FeatureTypeBuilder.newInstance(
"orgOreadMultiPolyBUILDER");
// TODO: Add a better check to ensure the name is unique.
// The name must be unique for repeated buffering. Name clashes probably
// fail in the memoryDataStore creation routine.
myFTBuilder.setName(myLayerName
+ ":Buffered-"
+ System.currentTimeMillis()
+ "ms");
myFTBuilder.setDefaultGeometry(myGT);
FeatureType myBufferFT = myFTBuilder.getFeatureType();
//////// 4.2: Now make the Feature
Feature myBufferF = null;
myBufferF = myBufferFT.create(new Object[] {z},
"orgOreadbufferedPointsFEATURE");
// TODO:Cleanup - remove.
System.out.println("Got to make the buffer Feature.");
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users