Hello Gustavo,
In SLD, you can provide a Rotation element that is based on each
feature rather than a constant. An example SLD doc and a program that
uses it are below. In the example, features have an "angle" attribute
which is assigned a value in degrees based on the point's X-ordinate.
This is used in the SLD doc to rotate a square marker.
Hope this helps,
Michael
rotated-points.sld
<?xml version="1.0" encoding="ISO-8859-1"?>
<StyledLayerDescriptor version="1.0.0"
xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd"
xmlns="http://www.opengis.net/sld"
xmlns:ogc="http://www.opengis.net/ogc"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<NamedLayer>
<Name>Rotated points</Name>
<UserStyle>
<Title>Demonstrates per-feature rotation</Title>
<FeatureTypeStyle>
<Rule>
<PointSymbolizer>
<Graphic>
<Mark>
<WellKnownName>square</WellKnownName>
<Stroke>
<CssParameter
name="stroke">#FF0000</CssParameter>
</Stroke>
</Mark>
<Size>18</Size>
<Rotation>
<ogc:PropertyName>angle</ogc:PropertyName>
</Rotation>
</Graphic>
</PointSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>
Example program: creates randomly placed points with symbol rotation
varying according to their position
package org.geotools.testing;
import java.util.Random;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.Point;
import org.geotools.data.simple.SimpleFeatureCollection;
import org.geotools.factory.CommonFactoryFinder;
import org.geotools.feature.FeatureCollections;
import org.geotools.feature.simple.SimpleFeatureBuilder;
import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
import org.geotools.geometry.jts.JTSFactoryFinder;
import org.geotools.geometry.jts.ReferencedEnvelope;
import org.geotools.map.MapContext;
import org.geotools.referencing.crs.DefaultEngineeringCRS;
import org.geotools.styling.SLDParser;
import org.geotools.styling.Style;
import org.geotools.swing.JMapFrame;
import org.opengis.feature.simple.SimpleFeatureType;
/**
*
* @author michael
*/
public class RotatedPointSymbols {
private static final ReferencedEnvelope BOUNDS =
new ReferencedEnvelope(0, 100, 0, 100,
DefaultEngineeringCRS.GENERIC_2D);
private static final int NUM_POINTS = 100;
public static void main(String[] args) throws Exception {
RotatedPointSymbols me = new RotatedPointSymbols();
me.displayRotatedPoints();
}
private void displayRotatedPoints() throws Exception {
SimpleFeatureCollection features = createPoints();
Style style = createStyle();
MapContext map = new MapContext();
map.addLayer(features, style);
JMapFrame.showMap(map);
}
private SimpleFeatureCollection createPoints() {
SimpleFeatureCollection fc = FeatureCollections.newCollection();
SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder();
typeBuilder.setName("mytype");
typeBuilder.add("shape", Point.class,
BOUNDS.getCoordinateReferenceSystem());
typeBuilder.add("angle", Double.class);
final SimpleFeatureType TYPE = typeBuilder.buildFeatureType();
SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(TYPE);
GeometryFactory geomFactory = JTSFactoryFinder.getGeometryFactory(null);
// Place points randomly and make angle a function of X-ordinate
Random rand = new Random();
for (int i = 0; i < NUM_POINTS; i++) {
double x = BOUNDS.getWidth() * rand.nextDouble();
double y = BOUNDS.getHeight() * rand.nextDouble();
Point p = geomFactory.createPoint(new Coordinate(x, y));
double angle = 90 * x / BOUNDS.getWidth();
featureBuilder.add(p);
featureBuilder.add(angle);
fc.add(featureBuilder.buildFeature(null));
}
return fc;
}
private Style createStyle() throws Exception {
SLDParser parser = new SLDParser(
CommonFactoryFinder.getStyleFactory(null),
getClass().getResource("/rotated-points.sld"));
Style[] styles = parser.readXML();
return styles[0];
}
}
On 18 May 2011 04:11, [email protected]
<[email protected]> wrote:
> Hey guys,
>
> I need to show arrows to display sea currents, but the problem is how I will
> rotate each arrow separately to indicate the current direction? Each arrow
> may have a 360° of variation and using a PointSymbolizer all my arrows have
> the same direction. Is there any way to solve this problem?
>
> Thanks,
>
> Gustavo Mesquita.
>
> --
> View this message in context:
> http://osgeo-org.1803224.n2.nabble.com/Problems-with-PointSymbolizer-tp6374444p6374444.html
> Sent from the geotools-gt2-users mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> Achieve unprecedented app performance and reliability
> What every C/C++ and Fortran developer should know.
> Learn how Intel has extended the reach of its next-generation tools
> to help boost performance applications - inlcuding clusters.
> http://p.sf.net/sfu/intel-dev2devmay
> _______________________________________________
> Geotools-gt2-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>
------------------------------------------------------------------------------
What Every C/C++ and Fortran developer Should Know!
Read this article and learn how Intel has extended the reach of its
next-generation tools to help Windows* and Linux* C/C++ and Fortran
developers boost performance applications - including clusters.
http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users