Thank you all for helping with the understanding of the basics of
Geotools! I have added a class that can read shapefiles and write
selections (made with a filter) to new shapefiles. Maybe others can use
this class to get a better understanding as well.

Most of the code I create is based on a post of a Steve Ansari
http://www.arcknowledge.com/gmane.comp.gis.geotools2.user/2006-07/msg000
59.html

Regards,

Jeroen

-----Original Message-----
From: Cole Markham [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, March 13, 2007 3:36 PM
To: Jeroen van Dijk
Cc: [email protected]
Subject: Re: [Geotools-gt2-users] GeometryFactory for a circle?

It took me a while to figure out how to create a filter as well, so I
will share my experience.
Now that you know how to create a geometry, you need to get the filter
factory and use that to create expressions which are used to build the
filter. You also need the schema (FeatureType) from the FeatureSource
that you want to filter on. Here is the code to create an intersection
filter. Creating a distance filter should be similar.

1. FilterFactory factory = FilterFactoryFinder.createFilterFactory();
2. PropertyName the_geom =
factory.property(schema.getDefaultGeometry().getName());
3. LiteralExpression geomExpression =
factory.createLiteralExpression(geometry);
4. Filter newFilter = factory.intersects(the_geom, geomExpression);

1. That is the org.geotools.filter.Factory which is deprecated, but to
my knowledge there is no other way to do it right now. You might have
noticed the opengis FilterFactory which accepts opengis Geometries,
but as you mentioned those are not compatible with the JTS Geometry
that you have.
2. The PropertyName expression represents the attribute in your target
FeatureSource that represents the geometry. Once you get the schema it
should work just the same as here.
3. The literal expression is the geometry itself. This method only
specifies Object, so it is not clear what values are acceptable. What
I am using there is a JTS geometry. I looked through the source and
that seems to be what the filters are expecting.
4. Then it's just as simple as creating the filter by calling the
appropriate method on the factory.

This works for me using Geotools 2.3.0. When I was looking the factory
didn't seem to have methods to create geometry filters in 2.2.x, but I
may have missed something.

Hope this helps,

Cole Markham


On 3/12/07, Jeroen van Dijk <[EMAIL PROTECTED]> wrote:
> Thanks for your help Teodor. I have looked into the JTS documentation
> and I know now how to create a point:
>
>         import com.vividsolutions.jts.geom.Coordinate;
>         import com.vividsolutions.jts.geom.CoordinateSequence;
>         import com.vividsolutions.jts.geom.GeometryFactory;
>         import com.vividsolutions.jts.geom.Point;
>         import
com.vividsolutions.jts.geom.impl.CoordinateArraySequence;
>
>         Coordinate [] coordArr = {new Coordinate(51.594f, 4.777f) };
>         CoordinateSequence cs = new CoordinateArraySequence( coordArr
);
>
>         GeometryFactory factory;
>         Point point = new Point(cs,  new GeometryFactory() );
>
>
> However, this point is not compatible with the GeoTools Point
interface
> because this is based on the  OpenGis interface and JTS Point class
> doesn't implement this. So how can I used this Point object with the
> Geotools library to make selection in a shapefile?
>
> Sorry for these questions but it is just not clear to me.
>
> Regards,
> Jeroen
>
>
> -----Original Message-----
> From: Teodor BACIU [mailto:[EMAIL PROTECTED]
> Sent: Monday, March 12, 2007 2:34 PM
> To: Jeroen van Dijk; [email protected]
> Subject: Re: [Geotools-gt2-users] GeometryFactory for a circle?
>
> On Mon, 12 Mar 2007 15:18:54 +0200, Jeroen van Dijk
<[EMAIL PROTECTED]>
>
> wrote:
>
> > Maybe, a silly question, but I still haven't solved my previous
posted
> > problem. My problems start quite basic: How do I create a point
> > Geometry?
> >
> > I guess I'm missing some basic knowledge of the API, but the
tutorials
> > do not help me here either.
> >
>
> Hi,
>
> Geotools is using for geometry operations the JTS
> API, developped by Vivid Solutions. You will have
> to familiarize yourself with this API first.
>
> As a start point you can check the following section
>  from the GeoTools tutorials:
>
>
http://geotools.codehaus.org/Working+with+JTS+Geometries+from+DataStores
>
> Best regards,
> Teodor
>
> >
> > -----Original Message-----
> > From: Ian Turton [mailto:[EMAIL PROTECTED]
> > Sent: Friday, March 09, 2007 10:10 PM
> > To: Jeroen van Dijk
> > Cc: [email protected]
> > Subject: Re: [Geotools-gt2-users] GeometryFactory for a circle?
> >
> > On 3/9/07, Jeroen van Dijk <[EMAIL PROTECTED]> wrote:
> >>
> >
> >>
> >> I want select roads, from a shapefile, with a certain radius from a
> > point,
> >> thus lying in a circle.
> >>
> >>
> >>
> >> I found this link that shows how to select point with a polygon.
> >>
> >> http://www.nabble.com/filter-points-within-polygon-t2740648.html
> >>
> >>
> >>
> >> My only problem is now to create a Geometry that represents a
circle.
> > Like
> >> in the post of
> >
> > What you really want is a DWithin filter which gives you everything
> > within a distance of a geometry (in your case a point).
> >
> > Ian
>
>
>
> --
> Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
>
>
------------------------------------------------------------------------
-
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to
share your
> opinions on IT & business topics through brief surveys-and earn cash
>
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDE
V
> _______________________________________________
> Geotools-gt2-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>

Attachment: GISFeatures.java
Description: GISFeatures.java

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to