Should I use a Polygon or a Mark?

22 messages Options
Embed this post
Permalink
1 2
jv-2

Should I use a Polygon or a Mark?

Reply Threaded More More options
Print post
Permalink
Hi everybody.  After being able to render some filled squares on a mapa using polygons now I want to expand the program in order to be able to draw several kind of  shapes: circles, squares, crosses (both filled and unfilled). Looks like the correct way to do it is by using Marks instead of polygons but I'm just unable to figure out how to add them to the FeatureCollection and how to set their coordinates.
I would be really grateful if anybody can write some hints.
Thanks!
jv
ps: btw I need to do it fully programatically, no by using a declarative file.

--
=======================================================
Javier Moreno
www.imaginafoto.com
=======================================================

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
Jody Garnett-2

Re: Should I use a Polygon or a Mark?

Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)
Have a look at the style layer descriptor specification; if you want to make up your own shapes you need an external mark; which can be a URL to an icon file.

Jody

On 07/09/2009, at 9:35 PM, jv wrote:

Hi everybody.  After being able to render some filled squares on a mapa using polygons now I want to expand the program in order to be able to draw several kind of  shapes: circles, squares, crosses (both filled and unfilled). Looks like the correct way to do it is by using Marks instead of polygons but I'm just unable to figure out how to add them to the FeatureCollection and how to set their coordinates.
I would be really grateful if anybody can write some hints.
Thanks!
jv
ps: btw I need to do it fully programatically, no by using a declarative file.

--
=======================================================
Javier Moreno
www.imaginafoto.com
=======================================================
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
jv-2

Re: Should I use a Polygon or a Mark?

Reply Threaded More More options
Print post
Permalink
Thanks Jody, but I don't understand how can I place the mark on the map: it only shows how to create the Style but no clue about how to make the layer. On the other hand, as usual, the example in the documentation doesn't compile with the last release, but I think I can make the proper changes.
Again, thanks.
jv

On Tue, Sep 8, 2009 at 1:40 AM, Jody Garnett <[hidden email]> wrote:
Have a look at the style layer descriptor specification; if you want to make up your own shapes you need an external mark; which can be a URL to an icon file.

Jody

On 07/09/2009, at 9:35 PM, jv wrote:

Hi everybody.  After being able to render some filled squares on a mapa using polygons now I want to expand the program in order to be able to draw several kind of  shapes: circles, squares, crosses (both filled and unfilled). Looks like the correct way to do it is by using Marks instead of polygons but I'm just unable to figure out how to add them to the FeatureCollection and how to set their coordinates.
I would be really grateful if anybody can write some hints.
Thanks!
jv
ps: btw I need to do it fully programatically, no by using a declarative file.

--
=======================================================
Javier Moreno
www.imaginafoto.com
=======================================================
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users




--
=======================================================
Javier Moreno
www.imaginafoto.com
=======================================================

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
mbedward

Re: Should I use a Polygon or a Mark?

Reply Threaded More More options
Print post
Permalink
Hi jv,

Sorry about the docs and the library being out of synch. Which page
were you looking at ?

Michael

2009/9/8 jv <[hidden email]>:
> Thanks Jody, but I don't understand how can I place the mark on the map: it
> only shows how to create the Style but no clue about how to make the layer.
> On the other hand, as usual, the example in the documentation doesn't
> compile with the last release, but I think I can make the proper changes.
> Again, thanks.
> jv

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
mbedward

Re: Should I use a Polygon or a Mark?

Reply Threaded More More options
Print post
Permalink
Yep, that was a pretty good speech :-)  And I wouldn't quibble with
any of it - I think you're quite right that the library needs to
become more developer friendly.

At the moment Jody and I (mostly Jody) are working through the
tutorial exercises in the Welcome section of the User Guide and
bringing them up to date, adding more comments etc. All of the classes
for these can be found in demo/example (the work is happening on trunk
in svn).

One of the things that is being revised at the moment is example code
for styling and rendering features. For your own questions, have a
look at the method createPointStyle() in:

http://svn.osgeo.org/geotools/trunk/demo/example/src/main/java/org/geotools/demo/ShapeLab.java

For the FOSS4G conference here in Sydney next month we (again, mostly
Jody) are putting together some tutorial material to support the
example code in this sort of format...

http://geotools.org/quickstart.html

So, hopefully this will make it a lot easier for people like you (and
me :) to get started on parts of the library that can otherwise be
very confusing or intimidating.

Michael

2009/9/8 jv <[hidden email]>:

> No need to apologize Michael, I understand it's not possible to keep it up
> to date. But I seriously think it should be some sample projects already
> configured to work in a cookbook style... I've already figured out how to
> create from the scratch a map with a layer and a few polygons on it but it
> has been a far from trivial experience.
> My desire is to migrate our projects to geotools (I'm working at the
> University of Barcelona) because it should allow us to bypass our lack of
> knowledgement around geographical concepts (we don't know, for example, how
> to properly draw a shape on different projections with accuracy) but if I
> have to be honest I'm finding quite painful to achieve even the most simple
> results.
> Both my boss and myself are willing to publish any code we generate but
> after spending two months on those tasks I'm also considering to postpone
> the development until geotools become more developer friendly. I would be
> really sad because I'm sincerely impressed by the capabilities of the
> library.
> Anyway, one think that really works here is the mail list: I'm very pleased
> to read your answers even if I cannot resolve my problems. Thanks for it.
> jv
> ps: oh!!! my god... sorry for the speech... the url of the document was
> http://docs.codehaus.org/display/GEOTDOC/06+Style+Layer+Descriptor+Document
> On Tue, Sep 8, 2009 at 1:44 PM, Michael Bedward <[hidden email]>
> wrote:
>>
>> Hi jv,
>>
>> Sorry about the docs and the library being out of synch. Which page
>> were you looking at ?
>>
>> Michael
>>
>> 2009/9/8 jv <[hidden email]>:
>> > Thanks Jody, but I don't understand how can I place the mark on the map:
>> > it
>> > only shows how to create the Style but no clue about how to make the
>> > layer.
>> > On the other hand, as usual, the example in the documentation doesn't
>> > compile with the last release, but I think I can make the proper
>> > changes.
>> > Again, thanks.
>> > jv
>
>
>
> --
> =======================================================
> Javier Moreno
> www.imaginafoto.com
> =======================================================
>

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
Jody Garnett-2

Re: Should I use a Polygon or a Mark?

Reply Threaded More More options
Print post
Permalink
In reply to this post by jv-2
Some javascript/style in this post has been disabled (why?)
Hi Jv:

In this case I would kindly ask you to review the style layer descriptor specification  (where our style model comes from). You may also find the sample sld files in the test cases to be of some use.

As Michael has mentioned we are working on some docs; and I always got stuck in writing docs for the style examples because I was not happy with the API (indeed it was not consistent and many methods were deprecated etc...). Last week I submitted a patch; and Andrea reviewed; and the style interfaces are now cleaned up.

So this is the week to bring together style documentation.

However I must say that I am only interested in bringing code examples showing how to do common things; for much of the advanced material there are plenty of nice references and so on - starting with the style layer description definition itself.

Here are a couple other links with examples:

These examples will be in XML but the data structure being represented is the same.

Happy hacking,
Jody

On 08/09/2009, at 8:41 PM, jv wrote:

Thanks Jody, but I don't understand how can I place the mark on the map: it only shows how to create the Style but no clue about how to make the layer. On the other hand, as usual, the example in the documentation doesn't compile with the last release, but I think I can make the proper changes.
Again, thanks.
jv

On Tue, Sep 8, 2009 at 1:40 AM, Jody Garnett <[hidden email]> wrote:
Have a look at the style layer descriptor specification; if you want to make up your own shapes you need an external mark; which can be a URL to an icon file.

Jody

On 07/09/2009, at 9:35 PM, jv wrote:

Hi everybody.  After being able to render some filled squares on a mapa using polygons now I want to expand the program in order to be able to draw several kind of  shapes: circles, squares, crosses (both filled and unfilled). Looks like the correct way to do it is by using Marks instead of polygons but I'm just unable to figure out how to add them to the FeatureCollection and how to set their coordinates.
I would be really grateful if anybody can write some hints.
Thanks!
jv
ps: btw I need to do it fully programatically, no by using a declarative file.

--
=======================================================
Javier Moreno
www.imaginafoto.com
=======================================================
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users




--
=======================================================
Javier Moreno
www.imaginafoto.com
=======================================================


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
mbedward

Re: Should I use a Polygon or a Mark?

Reply Threaded More More options
Print post
Permalink
2009/9/9 Jody Garnett <[hidden email]>:
> These examples will be in XML but the data structure being represented is
> the same.

But I think that illustrates part of the problem: you need to know
GeoTools style API quite well to translate XML examples to
programmatic examples in your head. So if you are new to the library
or styling it's catch-22.

Personally, I've found styling to be one of the most difficult aspects
of the library to master and, in part, I think that has been because
so much of the information here and elsewhere is written for users of
GeoServer and similar tools. There is relatively little about
programmatic use in stand-alone apps.

This is an observation rather than a criticism. Everyone here
struggles to find time to work on the docs.

Michael

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
Jody Garnett-2

Re: Should I use a Polygon or a Mark?

Reply Threaded More More options
Print post
Permalink
Good call Micheal - so let us ask the user list here for a shopping
list of examples; and once we get 2.6-M3 out the door we can swap code
examples back and forth in order to refine the docs; and the api.

I think styles also come across as hard as that is where the user
guide stops :-( Some code examples will go a long way here.

With that in mind here is an example of putting together a style with
an external graphic:
        StyleBuilder styleBuilder = new StyleBuilder();
        Style style = styleBuilder.createStyle();
        {
            {   PointSymbolizer pointSymbolizer =
styleBuilder.createPointSymbolizer();

                {   Graphic graphic = styleBuilder.createGraphic();
                    ExternalGraphic external =
styleBuilder.createExternalGraphic( "file:///C:/images/house.gif",
"image/gif");
                    graphic.graphicalSymbols().add( external );
                    graphic.graphicalSymbols().add(
styleBuilder.createMark("circle"));

                    pointSymbolizer.setGraphic(graphic);
                }
                Rule rule = styleBuilder.createRule(pointSymbolizer);
                FeatureTypeStyle featureTypeStyle =
styleBuilder.createFeatureTypeStyle("Feature", rule );
                style.featureTypeStyles().add( featureTypeStyle );
            }
        }

I have added this to the page
http://docs.codehaus.org/display/GEOTDOC/04+Styling
Jody

On Wed, Sep 9, 2009 at 12:16 PM, Michael
Bedward<[hidden email]> wrote:

> 2009/9/9 Jody Garnett <[hidden email]>:
>> These examples will be in XML but the data structure being represented is
>> the same.
>
> But I think that illustrates part of the problem: you need to know
> GeoTools style API quite well to translate XML examples to
> programmatic examples in your head. So if you are new to the library
> or styling it's catch-22.
>
> Personally, I've found styling to be one of the most difficult aspects
> of the library to master and, in part, I think that has been because
> so much of the information here and elsewhere is written for users of
> GeoServer and similar tools. There is relatively little about
> programmatic use in stand-alone apps.
>
> This is an observation rather than a criticism. Everyone here
> struggles to find time to work on the docs.
>
> Michael
>

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
jv-2

Re: Should I use a Polygon or a Mark?

Reply Threaded More More options
Print post
Permalink
You both really rock :-) I don't know if I will be able to find my way around the api but knowing you're so active in the mailing list really makes me think this project has a cool future.
I know part of my problem is that I don't have enough background information (for example, I  mix the concept of style and actual symbol on map placed at a determined coordinate). So don't take the next code very seriously, but I hope somebody will find it interesting: it creates layer from a series of coordinates placing a polygon of the indicated size for each xy pair. Depending of a parameter call fiability the color of the polygon changes.
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.LinearRing;
import com.vividsolutions.jts.geom.Polygon;
import edu.ub.bio.framework.SystemException;
import edu.ub.bio.wms.model.Fiability;
import java.awt.Color;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.geotools.data.memory.MemoryDataStore;
import org.geotools.feature.FeatureCollection;
import org.geotools.feature.simple.SimpleFeatureBuilder;
import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
import org.geotools.geometry.jts.JTSFactoryFinder;
import org.geotools.map.DefaultMapLayer;
import org.geotools.map.MapLayer;
import org.geotools.styling.Fill;
import org.geotools.styling.PolygonSymbolizer;
import org.geotools.styling.Style;
import org.geotools.styling.StyleBuilder;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.referencing.crs.CoordinateReferenceSystem;

/**
 *
 * @author ciberado
 */
public class UTMMapLayerBuilder {

  private MemoryDataStore dataStore;
  private CoordinateReferenceSystem crs;
  private Map<Fiability, SimpleFeatureType> featureTypes =
  new HashMap<Fiability, SimpleFeatureType>();

  public UTMMapLayerBuilder(CoordinateReferenceSystem crs) {
  this.dataStore = new MemoryDataStore();
  this.crs = crs;
  for (Fiability fiab : Fiability.values()) {
  featureTypes.put(fiab, createSpeciesFeatureType(fiab));
  }
  }

  public void addSquare(String id, String name, double x, double y,
  double size, Fiability fiability) {
  Polygon polygon = createPolygon(x, y, size);

  SimpleFeature feature = SimpleFeatureBuilder.build(
  featureTypes.get(fiability),
  new Object[]{polygon, name}, id);
  dataStore.addFeature(feature);
  }

  public MapLayer buildLayer(Color color) {
  try {
  DefaultMapLayer layer = null;
  for (String currentName : dataStore.getTypeNames()) {
  StyleBuilder builder = new StyleBuilder();
  PolygonSymbolizer symbolizer = builder.createPolygonSymbolizer(color);
  Fiability fiability = Fiability.valueOf(currentName);
  Fill fill = createFillByFiability(builder, color, fiability);
  symbolizer.setFill(fill);

  Style style = builder.createStyle(symbolizer);
  FeatureCollection featureCollection = 
  dataStore.getFeatureSource(currentName).getFeatures();
  layer = new DefaultMapLayer(featureCollection, style);
  layer.setTitle("SpeciesList");
  }
  return layer;
  } catch (IOException e) {
  throw new SystemException(e);
  }
  }

  private Fill createFillByFiability(StyleBuilder builder, Color color, Fiability fiability) {
  Fill fill;

  switch (fiability) {
  case DISAPPEARED : fill = builder.createFill(Color.BLACK, 0.33); break;
  case SURE : fill = builder.createFill(Color.GREEN, 0.33); break;
  case UNSURE : fill = builder.createFill(Color.ORANGE, 0.33); break;
  case UNKNOWN : fill = builder.createFill(Color.BLUE, 0.33); break;

  default: fill = null;
  }

  return fill;
  }

  private SimpleFeatureType createSpeciesFeatureType(Fiability fiability) {
  SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
  builder.setName(fiability.name());
  builder.setNamespaceURI("http://biodiver.bio.ub.es/geo");
  builder.setCRS(crs);
  builder.add("squareGeometry", Polygon.class);
  builder.add("speciesName", String.class);
  SimpleFeatureType featureType = builder.buildFeatureType();
  return featureType;
  }

  private static Polygon createPolygon(double x, double y, double size) {
  GeometryFactory gf = JTSFactoryFinder.getGeometryFactory(null);
  Coordinate[] polygonCoordinates = new Coordinate[5];
  polygonCoordinates[0] = new Coordinate(x, y);
  polygonCoordinates[1] = new Coordinate(x + size, y);
  polygonCoordinates[2] = new Coordinate(x + size, y + size);
  polygonCoordinates[3] = new Coordinate(x, y + size);
  polygonCoordinates[4] = polygonCoordinates[0];
  LinearRing ring = gf.createLinearRing(polygonCoordinates);
  Polygon polygon = gf.createPolygon(ring, null);

  return polygon;

  }
}



On Wed, Sep 9, 2009 at 9:48 AM, Jody Garnett <[hidden email]> wrote:
Good call Micheal - so let us ask the user list here for a shopping
list of examples; and once we get 2.6-M3 out the door we can swap code
examples back and forth in order to refine the docs; and the api.

I think styles also come across as hard as that is where the user
guide stops :-( Some code examples will go a long way here.

With that in mind here is an example of putting together a style with
an external graphic:
       StyleBuilder styleBuilder = new StyleBuilder();
       Style style = styleBuilder.createStyle();
       {
           {   PointSymbolizer pointSymbolizer =
styleBuilder.createPointSymbolizer();

               {   Graphic graphic = styleBuilder.createGraphic();
                   ExternalGraphic external =
styleBuilder.createExternalGraphic( "file:///C:/images/house.gif",
"image/gif");
                   graphic.graphicalSymbols().add( external );
                   graphic.graphicalSymbols().add(
styleBuilder.createMark("circle"));

                   pointSymbolizer.setGraphic(graphic);
               }
               Rule rule = styleBuilder.createRule(pointSymbolizer);
               FeatureTypeStyle featureTypeStyle =
styleBuilder.createFeatureTypeStyle("Feature", rule );
               style.featureTypeStyles().add( featureTypeStyle );
           }
       }

I have added this to the page
http://docs.codehaus.org/display/GEOTDOC/04+Styling
Jody

On Wed, Sep 9, 2009 at 12:16 PM, Michael
Bedward<[hidden email]> wrote:
> 2009/9/9 Jody Garnett <[hidden email]>:
>> These examples will be in XML but the data structure being represented is
>> the same.
>
> But I think that illustrates part of the problem: you need to know
> GeoTools style API quite well to translate XML examples to
> programmatic examples in your head. So if you are new to the library
> or styling it's catch-22.
>
> Personally, I've found styling to be one of the most difficult aspects
> of the library to master and, in part, I think that has been because
> so much of the information here and elsewhere is written for users of
> GeoServer and similar tools. There is relatively little about
> programmatic use in stand-alone apps.
>
> This is an observation rather than a criticism. Everyone here
> struggles to find time to work on the docs.
>
> Michael
>



--
=======================================================
Javier Moreno
www.imaginafoto.com
=======================================================

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
mbedward

Re: Should I use a Polygon or a Mark?

Reply Threaded More More options
Print post
Permalink
Hi jv,

I just had a look at your code - only very quickly so correct me if I
things wrong below...

Firstly, always pleased to see someone using GeoTools for species
conservation apps :-)  That's my area as well.

Rather than creating a feature type for each of your status categories
(Fiability enum ?) it would be more convenient for you to have a
single feature type, with attributes for species, position, status...
Then, when rendering the features, have a Style that links the symbol
/ color / fill to the status value.

Is that the sort of thing you're after ?

Michael

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
jv-2

Re: Should I use a Polygon or a Mark?

Reply Threaded More More options
Print post
Permalink
That's exactly what I'm looking for :-) And it's nice to know you're also in the same field... my boss has some millions of citations in a database and we're trying to publish that information in several ways. The first (in theory) little project we want to write with gt is to migrate our tiny wms server to this platform.
The second  (and by far more interesting) project will be to create a multimedia-gps-based guide. That's why we need the power of gt: we don't know how to correctly work with several projections on our own.
Now I realise that polygons are more convenient in order to surround an area of the map, not to place marks on a determined spot. But I still don't know how to do it. If I understand you correctly the steps are something like this:
- create a single featuretype with the "schema" of the information of a bio citation (at least name, x,y, status)
- instantiate several features of that featureType, one for each citation.
- create as many styles as status values.
- link every kind of style with the set of features that share the matching status.
- create a layer from all those features.
The main problem is still I don't know how to express the coordinates as  attributes of a featuretype... perhaps is enough to add them with a particular name? And I'm also not  sure how to link the styles with the features.
You're being really patient. I promise I'll try to write a short tutorial about all of this once I feel more comfortable with the library. And of course both Jody and you have as many beers paid as you want if you come to Barcelona ;-)
jv

On Wed, Sep 9, 2009 at 12:27 PM, Michael Bedward <[hidden email]> wrote:
Hi jv,

I just had a look at your code - only very quickly so correct me if I
things wrong below...

Firstly, always pleased to see someone using GeoTools for species
conservation apps :-)  That's my area as well.

Rather than creating a feature type for each of your status categories
(Fiability enum ?) it would be more convenient for you to have a
single feature type, with attributes for species, position, status...
Then, when rendering the features, have a Style that links the symbol
/ color / fill to the status value.

Is that the sort of thing you're after ?

Michael



--
=======================================================
Javier Moreno
www.imaginafoto.com
=======================================================

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
Jody Garnett-2

Re: Should I use a Polygon or a Mark?

Reply Threaded More More options
Print post
Permalink
In reply to this post by jv-2
Some javascript/style in this post has been disabled (why?)

On 09/09/2009, at 6:07 PM, jv wrote:

You both really rock :-) I don't know if I will be able to find my way around the api but knowing you're so active in the mailing list really makes me think this project has a cool future.

You did arrive exactly when we needed you - ie when we are needing feedback on style usability. So in that sense we both lucked out.

I know part of my problem is that I don't have enough background information (for example, I  mix the concept of style and actual symbol on map placed at a determined coordinate).

Not sure I understand the difference?

So don't take the next code very seriously, but I hope somebody will find it interesting: it creates layer from a series of coordinates placing a polygon of the indicated size for each xy pair. Depending of a parameter call fiability the color of the polygon changes.

    private Fill createFillByFiability(StyleBuilder builder, Color color, Fiability fiability) {
  Fill fill;

  switch (fiability) {
  case DISAPPEARED : fill = builder.createFill(Color.BLACK, 0.33); break;
  case SURE : fill = builder.createFill(Color.GREEN, 0.33); break;
  case UNSURE : fill = builder.createFill(Color.ORANGE, 0.33); break;
  case UNKNOWN : fill = builder.createFill(Color.BLUE, 0.33); break;

  default: fill = null;
  }

Yeah okay. You are doing conditional logic in java code; which is fine - however if "fiability" was an attribute in your feature we would rather you set up a series of "Rules" one for each case; each with its on Symboliser.  

I had a little trouble reading through your code (so I may of not understood what you were doing very well).

Jody


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
mbedward

Re: Should I use a Polygon or a Mark?

Reply Threaded More More options
Print post
Permalink
Hi jv,

Below is some demo code that illustrates:

- creating a common feature type with point geometry for location and
an attribute for species status

- creating features and adding them to a feature collection

- creating a rendering style to use different symbols depending on
status value of a feature

- creating a map and displaying it with the JMapFrame.showMap static method

To run this code right now you will need to be using the bleeding edge
GeoTools: 2.6-SNAPSHOT.

Give us some feedback and we can turn more of this into examples and
docs for the GeoTools site.

Michael

import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.Point;
import java.awt.Color;
import java.util.HashMap;
import java.util.Map;
import org.geotools.factory.CommonFactoryFinder;
import org.geotools.feature.FeatureCollection;
import org.geotools.feature.FeatureCollections;
import org.geotools.feature.simple.SimpleFeatureBuilder;
import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
import org.geotools.map.DefaultMapContext;
import org.geotools.map.DefaultMapLayer;
import org.geotools.map.MapContext;
import org.geotools.map.MapLayer;
import org.geotools.referencing.crs.DefaultGeographicCRS;
import org.geotools.styling.FeatureTypeStyle;
import org.geotools.styling.Graphic;
import org.geotools.styling.Mark;
import org.geotools.styling.PointSymbolizer;
import org.geotools.styling.Rule;
import org.geotools.styling.Style;
import org.geotools.styling.StyleBuilder;
import org.geotools.swing.JMapFrame;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.filter.FilterFactory;
import org.opengis.referencing.crs.CoordinateReferenceSystem;


/**
 * Demonstrates creating a feature type with a field that will be used to
 * control point symbols for rendering the features
 */

public class SpeciesStatus {

    public enum Status {
        DISAPPEARED(1, Color.BLACK),
        SURE(2, Color.GREEN),
        UNSURE(3, Color.CYAN),
        UNKNOWN(4, Color.GRAY);

        /* a map for reverse lookup */
        private static Map<Integer, Status> lookup;
        static {
            lookup = new HashMap<Integer, Status>();
            for (Status status : Status.values()) {
                lookup.put(status.getCode(), status);
            }
        }

        private int code;
        private Color color;

        private Status(int code, Color color) {
            this.code = code;
            this.color = color;
        }

        public int getCode() {
            return code;
        }

        public Color getColor() {
            return color;
        }

        public static Status get(int code) {
            return lookup.get(code);
        }
    }

    private CoordinateReferenceSystem crs;
    private SimpleFeatureType featureType;
    private SimpleFeatureBuilder featureBuilder;
    private GeometryFactory geomFactory;

    private FeatureCollection<SimpleFeatureType, SimpleFeature> featureColl;
    private Style style;


    public SpeciesStatus(CoordinateReferenceSystem crs) {
        this.crs = crs;
        this.featureColl = FeatureCollections.newCollection();

        createFeatureType();
        createStyle();
    }

    private void createFeatureType() {
        SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
        builder.setName("species_rec");
        builder.setCRS(crs);
        builder.add("the_geom", Point.class);  // geometry field
        builder.add("speciesId", String.class);  // alpha-numeric ID for species
        builder.add("status", Integer.class);  // integer status code

        featureType =  builder.buildFeatureType();
    }

    /**
     * Create a Style with a Rule for each of the Status values
     * that we want to render as different symbols
     */
    public void createStyle() {
        FilterFactory ff = CommonFactoryFinder.getFilterFactory2(null);
        StyleBuilder sb = new StyleBuilder();

        Rule[] rules = new Rule[Status.values().length];

        int k = 0;
        for (Status status : Status.values()) {

            Graphic graphic = sb.createGraphic();

            // remove the default symbol (a bit clunky)
            graphic.graphicalSymbols().clear();

            // create a new symbol
            Mark mark = sb.createMark(StyleBuilder.MARK_CIRCLE,
status.getColor());
            graphic.graphicalSymbols().add(mark);

            // our point symbolizer to use this symbol
            PointSymbolizer sym = sb.createPointSymbolizer(graphic);

            // a rule that will select features to render with this status value
            Rule rule = sb.createRule(sym);
            rule.setFilter(ff.equals(ff.property("status"),
ff.literal(status.getCode())));
            rules[k++] = rule;
        }

        // put all our rules together in a FeatureTypeStyle
        FeatureTypeStyle fts =
sb.createFeatureTypeStyle(featureType.getTypeName(), rules);

        this.style = sb.createStyle();
        style.featureTypeStyles().add(fts);
    }

    /**
     * Add a new feature to out collection
     * @param speciesId alpha-numeric species Id
     * @param x location X coord (world)
     * @param y location Y coord (world)
     * @param status the species status category
     */
    public void addFeature(String speciesId, double x, double y,
Status status) {
        if (geomFactory == null) {
            geomFactory = new GeometryFactory();
        }

        if (featureBuilder == null) {
            featureBuilder = new SimpleFeatureBuilder(featureType);
        }

        Geometry pos = geomFactory.createPoint(new Coordinate(x, y));

        featureBuilder.add(pos);
        featureBuilder.add(speciesId);
        featureBuilder.add(status.getCode());

        SimpleFeature feature = featureBuilder.buildFeature(null);
        featureColl.add(feature);
    }

    /**
     * Run the demo (args are ignored)
     */
    public static void main(String[] args) {
        SpeciesStatus me = new SpeciesStatus(DefaultGeographicCRS.WGS84);
        me.demo();
    }

    /**
     * Demo: creates a few features with different Status values
     * and adds them to the FeaureCollection. Then displays them
     * as a map.
     */
    private void demo() {
        addFeature("lynx", 2.0, 41.0, Status.UNKNOWN);
        addFeature("bear", 3.0, 42.0, Status.SURE);
        addFeature("bear", 3.5, 41.5, Status.DISAPPEARED);
        addFeature("yeti", 2.5, 42.5, Status.UNSURE);

        MapContext map = new DefaultMapContext(crs);
        map.setTitle("Species status");

        MapLayer layer = new DefaultMapLayer(featureColl, style);
        map.addLayer(layer);

        JMapFrame.showMap(map);
    }

}

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
iceDice

Re: Should I use a Polygon or a Mark?

Reply Threaded More More options
Print post
Permalink
Hello,

I tried to run that code, i use gt-main-2.6-SNAPSHOT.jar but i got error on following line:

style.featureTypeStyles().add(fts);
The method add(capture#1-of ? extends FeatureTypeStyle) in the type List<capture#1-of ? extends FeatureTypeStyle> is not applicable for the arguments (FeatureTypeStyle).

Maybe i am using bad gt-main library?
I downloaded it from http://repo.opengeo.org/org/geotools/.

Thanks.


mbedward wrote:
Hi jv,

Below is some demo code that illustrates:

- creating a common feature type with point geometry for location and
an attribute for species status

- creating features and adding them to a feature collection

- creating a rendering style to use different symbols depending on
status value of a feature

- creating a map and displaying it with the JMapFrame.showMap static method

To run this code right now you will need to be using the bleeding edge
GeoTools: 2.6-SNAPSHOT.

Give us some feedback and we can turn more of this into examples and
docs for the GeoTools site.

Michael

import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.Point;
import java.awt.Color;
import java.util.HashMap;
import java.util.Map;
import org.geotools.factory.CommonFactoryFinder;
import org.geotools.feature.FeatureCollection;
import org.geotools.feature.FeatureCollections;
import org.geotools.feature.simple.SimpleFeatureBuilder;
import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
import org.geotools.map.DefaultMapContext;
import org.geotools.map.DefaultMapLayer;
import org.geotools.map.MapContext;
import org.geotools.map.MapLayer;
import org.geotools.referencing.crs.DefaultGeographicCRS;
import org.geotools.styling.FeatureTypeStyle;
import org.geotools.styling.Graphic;
import org.geotools.styling.Mark;
import org.geotools.styling.PointSymbolizer;
import org.geotools.styling.Rule;
import org.geotools.styling.Style;
import org.geotools.styling.StyleBuilder;
import org.geotools.swing.JMapFrame;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.filter.FilterFactory;
import org.opengis.referencing.crs.CoordinateReferenceSystem;


/**
 * Demonstrates creating a feature type with a field that will be used to
 * control point symbols for rendering the features
 */

public class SpeciesStatus {

    public enum Status {
        DISAPPEARED(1, Color.BLACK),
        SURE(2, Color.GREEN),
        UNSURE(3, Color.CYAN),
        UNKNOWN(4, Color.GRAY);

        /* a map for reverse lookup */
        private static Map<Integer, Status> lookup;
        static {
            lookup = new HashMap<Integer, Status>();
            for (Status status : Status.values()) {
                lookup.put(status.getCode(), status);
            }
        }

        private int code;
        private Color color;

        private Status(int code, Color color) {
            this.code = code;
            this.color = color;
        }

        public int getCode() {
            return code;
        }

        public Color getColor() {
            return color;
        }

        public static Status get(int code) {
            return lookup.get(code);
        }
    }

    private CoordinateReferenceSystem crs;
    private SimpleFeatureType featureType;
    private SimpleFeatureBuilder featureBuilder;
    private GeometryFactory geomFactory;

    private FeatureCollection<SimpleFeatureType, SimpleFeature> featureColl;
    private Style style;


    public SpeciesStatus(CoordinateReferenceSystem crs) {
        this.crs = crs;
        this.featureColl = FeatureCollections.newCollection();

        createFeatureType();
        createStyle();
    }

    private void createFeatureType() {
        SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
        builder.setName("species_rec");
        builder.setCRS(crs);
        builder.add("the_geom", Point.class);  // geometry field
        builder.add("speciesId", String.class);  // alpha-numeric ID for species
        builder.add("status", Integer.class);  // integer status code

        featureType =  builder.buildFeatureType();
    }

    /**
     * Create a Style with a Rule for each of the Status values
     * that we want to render as different symbols
     */
    public void createStyle() {
        FilterFactory ff = CommonFactoryFinder.getFilterFactory2(null);
        StyleBuilder sb = new StyleBuilder();

        Rule[] rules = new Rule[Status.values().length];

        int k = 0;
        for (Status status : Status.values()) {

            Graphic graphic = sb.createGraphic();

            // remove the default symbol (a bit clunky)
            graphic.graphicalSymbols().clear();

            // create a new symbol
            Mark mark = sb.createMark(StyleBuilder.MARK_CIRCLE,
status.getColor());
            graphic.graphicalSymbols().add(mark);

            // our point symbolizer to use this symbol
            PointSymbolizer sym = sb.createPointSymbolizer(graphic);

            // a rule that will select features to render with this status value
            Rule rule = sb.createRule(sym);
            rule.setFilter(ff.equals(ff.property("status"),
ff.literal(status.getCode())));
            rules[k++] = rule;
        }

        // put all our rules together in a FeatureTypeStyle
        FeatureTypeStyle fts =
sb.createFeatureTypeStyle(featureType.getTypeName(), rules);

        this.style = sb.createStyle();
        style.featureTypeStyles().add(fts);
    }

    /**
     * Add a new feature to out collection
     * @param speciesId alpha-numeric species Id
     * @param x location X coord (world)
     * @param y location Y coord (world)
     * @param status the species status category
     */
    public void addFeature(String speciesId, double x, double y,
Status status) {
        if (geomFactory == null) {
            geomFactory = new GeometryFactory();
        }

        if (featureBuilder == null) {
            featureBuilder = new SimpleFeatureBuilder(featureType);
        }

        Geometry pos = geomFactory.createPoint(new Coordinate(x, y));

        featureBuilder.add(pos);
        featureBuilder.add(speciesId);
        featureBuilder.add(status.getCode());

        SimpleFeature feature = featureBuilder.buildFeature(null);
        featureColl.add(feature);
    }

    /**
     * Run the demo (args are ignored)
     */
    public static void main(String[] args) {
        SpeciesStatus me = new SpeciesStatus(DefaultGeographicCRS.WGS84);
        me.demo();
    }

    /**
     * Demo: creates a few features with different Status values
     * and adds them to the FeaureCollection. Then displays them
     * as a map.
     */
    private void demo() {
        addFeature("lynx", 2.0, 41.0, Status.UNKNOWN);
        addFeature("bear", 3.0, 42.0, Status.SURE);
        addFeature("bear", 3.5, 41.5, Status.DISAPPEARED);
        addFeature("yeti", 2.5, 42.5, Status.UNSURE);

        MapContext map = new DefaultMapContext(crs);
        map.setTitle("Species status");

        MapLayer layer = new DefaultMapLayer(featureColl, style);
        map.addLayer(layer);

        JMapFrame.showMap(map);
    }

}

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Geotools-gt2-users mailing list
Geotools-gt2-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
mbedward

Re: Should I use a Polygon or a Mark?

Reply Threaded More More options
Print post
Permalink
2009/9/10 iceDice wrote:
>
> I tried to run that code, i use gt-main-2.6-SNAPSHOT.jar but i got error on
> following line:

Hello,

Works for me :-)

I'm guessing that the problem is that you are not using the
2.6-SNAPSHOT for the other required geotools jars as well.

Do you use maven or are you getting the jars manually ?

Michael

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
Jody Garnett-2

Re: Should I use a Polygon or a Mark?

Reply Threaded More More options
Print post
Permalink
In reply to this post by iceDice
Hi Guys:

We have to wait for the build machine to publish a new SNAPSHOT (which
it does every day). Michael you can kick the hudson machine to release
a snapshot if you like ... an array of FeatureTypeStyle[] - and we
have now made the internal list available.

Jody

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
jv-2

Re: Should I use a Polygon or a Mark?

Reply Threaded More More options
Print post
Permalink
You're the best. I'm currently fighting against a rebellion in the servers that claim there's not javax.media.jai.warpaffine class but once I solve it I'll dive into the links and code you've write. Thanks thanks thanks!

jv

On Thu, Sep 10, 2009 at 11:54 AM, Jody Garnett <[hidden email]> wrote:
Hi Guys:

We have to wait for the build machine to publish a new SNAPSHOT (which
it does every day). Michael you can kick the hudson machine to release
a snapshot if you like ... an array of FeatureTypeStyle[] - and we
have now made the internal list available.

Jody

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users



--
=======================================================
Javier Moreno
www.imaginafoto.com
=======================================================

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
jv-2

Re: Should I use a Polygon or a Mark?

Reply Threaded More More options
Print post
Permalink
Hi! This is the code I've been working for some time in order to
create an UTM map with a series of areas marked with a circle, a cross
or a square. Without the fantastic help provided by Jody and Michael I
would be unable to achieve it, so many thanks dudes!

Next phase will include adding actual marks on the map in order to
show point-size features.


============================================================================


package edu.ub.bio.wms.model;

public enum Fiability {

  UNKNOWN, UNSURE, SURE, DISAPPEARED;

}

============================================================================

package edu.ub.bio.wms.mapa;

import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.LinearRing;
import com.vividsolutions.jts.geom.Polygon;
import edu.ub.bio.framework.SystemException;
import edu.ub.bio.wms.model.Fiability;
import java.awt.Color;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.geotools.data.memory.MemoryDataStore;
import org.geotools.feature.FeatureCollection;
import org.geotools.feature.simple.SimpleFeatureBuilder;
import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
import org.geotools.geometry.jts.JTSFactoryFinder;
import org.geotools.map.DefaultMapLayer;
import org.geotools.map.MapLayer;
import org.geotools.styling.Fill;
import org.geotools.styling.PolygonSymbolizer;
import org.geotools.styling.Style;
import org.geotools.styling.StyleBuilder;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.referencing.crs.CoordinateReferenceSystem;

/**
 *
 * @author ciberado
 */
public class UTMMapLayerBuilder {

  private MemoryDataStore dataStore;
  private CoordinateReferenceSystem crs;
  private Map<Fiability, SimpleFeatureType> featureTypes =
  new HashMap<Fiability, SimpleFeatureType>();

  public UTMMapLayerBuilder(CoordinateReferenceSystem crs) {
  this.dataStore = new MemoryDataStore();
  this.crs = crs;
  for (Fiability fiab : Fiability.values()) {
  featureTypes.put(fiab, createSpeciesFeatureType(fiab));
  }
  }

  public void addRegion(String id, String name, double x, double y,
  double size, Fiability fiability) {
  Geometry polygon = null;
  switch (fiability) {
  case DISAPPEARED : polygon = createCrossPolygon(x, y, size); break;
  case UNSURE : polygon = createCirclePolygon(x, y, size); break;
  default : polygon = createSquarePolygon(x, y, size); break;
  }

  SimpleFeature feature = SimpleFeatureBuilder.build(
  featureTypes.get(fiability),
  new Object[]{polygon, name}, id);
  dataStore.addFeature(feature);
  }

  public MapLayer buildLayer(Color color) {
  try {
  DefaultMapLayer layer = null;
  for (String currentName : dataStore.getTypeNames()) {
  StyleBuilder builder = new StyleBuilder();
  PolygonSymbolizer symbolizer = builder.createPolygonSymbolizer(color);
  Fiability fiability = Fiability.valueOf(currentName);
  Fill fill = createFillByFiability(builder, color, fiability);
  symbolizer.setFill(fill);

  Style style = builder.createStyle(symbolizer);
  FeatureCollection featureCollection =
  dataStore.getFeatureSource(currentName).getFeatures();
  layer = new DefaultMapLayer(featureCollection, style);
  layer.setTitle("SpeciesList");
  }
  return layer;
  } catch (IOException e) {
  throw new SystemException(e);
  }
  }

  private Fill createFillByFiability(StyleBuilder builder, Color
color, Fiability fiability) {
  Fill fill;

  switch (fiability) {
  case DISAPPEARED : fill = builder.createFill(Color.BLACK, 0.33); break;
  case SURE : fill = builder.createFill(Color.GREEN, 0.33); break;
  case UNSURE : fill = builder.createFill(Color.ORANGE, 0.33); break;
  case UNKNOWN : fill = builder.createFill(Color.BLUE, 0.33); break;

  default: fill = null;
  }

  return fill;
  }

  private SimpleFeatureType createSpeciesFeatureType(Fiability fiability) {
  SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
  builder.setName(fiability.name());
  builder.setNamespaceURI("http://biodiver.bio.ub.es/geo");
  builder.setCRS(crs);
  builder.add("squareGeometry", Polygon.class);
  builder.add("speciesName", String.class);
  SimpleFeatureType featureType = builder.buildFeatureType();
  return featureType;
  }

  private static Geometry createSquarePolygon(double x, double y, double size) {
  GeometryFactory gf = JTSFactoryFinder.getGeometryFactory(null);
  Coordinate[] polygonCoordinates = new Coordinate[5];
  polygonCoordinates[0] = new Coordinate(x, y);
  polygonCoordinates[1] = new Coordinate(x + size, y);
  polygonCoordinates[2] = new Coordinate(x + size, y + size);
  polygonCoordinates[3] = new Coordinate(x, y + size);
  polygonCoordinates[4] = polygonCoordinates[0];
  LinearRing ring = gf.createLinearRing(polygonCoordinates);
  Polygon polygon = gf.createPolygon(ring, null);

  return polygon;

  }

  private static Geometry createCirclePolygon(double x, double y,
final double size) {
  final int SIDES = 48;
  double radio = size / 2;
  x = x + radio / 2;
  y = y + radio / 2;
  GeometryFactory factory = JTSFactoryFinder.getGeometryFactory(null);
  Coordinate coords[] = new Coordinate[SIDES+1];
  for( int i = 0; i < SIDES; i++){
  double angle = ((double) i / (double) SIDES) * Math.PI * 2.0;
  double dx = Math.cos( angle ) * radio;
  double dy = Math.sin( angle ) * radio;
  coords[i] = new Coordinate( (double) x + dx, (double) y + dy );
  }
  coords[SIDES] = coords[0];

  LinearRing ring = factory.createLinearRing( coords );
  Polygon polygon = factory.createPolygon( ring, null );

  return polygon;
  }

  private static Geometry createCrossPolygon(double x, double y, double size) {
  GeometryFactory gf = JTSFactoryFinder.getGeometryFactory(null);
  double s = size / 3 *1.05;
  double ss = size /2;
  double sss = size * 0.95;
  double[] xy = {
  s,0,
  s,s,
  0,s,
  0,ss,
  s,ss,
  s,sss,
  ss,sss,
  ss,ss,
  sss,ss,
  sss,s,
  ss,s,
  ss,0,
  s,0
  };

  Coordinate[] polygonCoordinates = new Coordinate[xy.length / 2];
  for (int idx=0; idx < polygonCoordinates.length; idx++) {
  polygonCoordinates[idx] = new Coordinate(x+xy[idx*2], y+xy[idx*2+1]);
  }
  LinearRing ring = gf.createLinearRing(polygonCoordinates);
  Polygon polygon = gf.createPolygon(ring, null);

  return polygon;

  }

}


============================================================================

Little example about how to use it:

double minx = 0;
double miny = 0;
double maxx = 50;
double maxy = 50;

crs = CRS.decode("EPSG:32631");
UTMMapLayerBuilder layerBuilder = new UTMMapLayerBuilder(crs);
layerBuilder.addRegion("point_" + idx, 5, 5, 10, Fiability.UNSURE);
layerBuilder.addRegion("point_" + idx, 25, 35, 10, Fiability.SURE);
layerBuilder.addRegion("point_" + idx, 5, 25, 10, Fiability.DISAPPEARED);
BufferedImage image =
        new BufferedImage(getImageWidth(), getImageHeight(),
                          BufferedImage.TYPE_INT_ARGB);
HashMap hints = new HashMap();
hints.put("optimizedDataLoadingEnabled", Boolean.TRUE);
hints.put(RenderingHints.VALUE_RENDER_QUALITY, Boolean.TRUE);
hints.put(RenderingHints.VALUE_ANTIALIAS_ON, Boolean.TRUE);

GTRenderer renderer = new StreamingRenderer();
renderer.setRendererHints(hints);

MapLayer mapLayer = layerBuilder.buildLayer(styleToColor(getStyle()));

if (mapLayer != null) {
    MapContext mapContext = new GraphicEnhancedMapContext(
            new MapLayer[] {mapLayer}, crs);

    renderer.setContext(mapContext);

    Coordinate c1 = new Coordinate(minx, miny);
    Coordinate c2 = new Coordinate(maxx, maxy);

    Envelope activeArea = new Envelope(c1, c2);
    mapContext.setAreaOfInterest(activeArea, crs);

    Graphics2D g = image.createGraphics();
    renderer.paint(g, new Rectangle(getImageWidth(), getImageHeight()),
                   activeArea);
}

------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
mbedward

Re: Should I use a Polygon or a Mark?

Reply Threaded More More options
Print post
Permalink
Hi jv,

Judging by your code you're obviously starting to find your way around
GeoTools pretty well :)

Sorry to be vague but can you tell me (possibly again) why you want to
construct your own polygons rather than use marks for point locations
?

Michael

------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
jv-2

Re: Should I use a Polygon or a Mark?

Reply Threaded More More options
Print post
Permalink
hahaha of course Michael: Our coordinates are not plots but regions of
10km2 so maybe I'm wrong but I think it's more accurate to use a
polygon. Umh... Am I actually wrong? ^_^

On Wed, Sep 23, 2009 at 7:17 AM, Michael Bedward
<[hidden email]> wrote:

> Hi jv,
>
> Judging by your code you're obviously starting to find your way around
> GeoTools pretty well :)
>
> Sorry to be vague but can you tell me (possibly again) why you want to
> construct your own polygons rather than use marks for point locations
> ?
>
> Michael
>



--
=======================================================
Javier Moreno
www.imaginafoto.com
=======================================================

------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
1 2