|
From: Martin S. <sp...@mo...> - 2005-10-11 16:14:36
|
Hi,
I have an additional question about this topic:
I use StyledMapPane to show raster data (287x275 cells; cell size is
500x500 meters). In a JLabel the world coordinates and the raster value
of the current mouse position are displayed (I placed my code example
below).
But it does not work exactly! The raster value, which is shown in the
label does not fit to the cell (color) my mouse cursor is over (1=green,
2=blue, 3=yellow, 4=red, 5=cyan).
If you look at the attached picture, you can see that it is displaced
about nearly 9 (not exactly! could also be 8.7 or something like that)
cells in east/west direction (I drew the return of
GridCoverage.evaluate(Point2D,.) into the picture underlied with the
corresponding color).
For example:
- if I move the cursor over the green cell, the displayed value ("5") is
of the cell, which is 9 cells right of it.
- the real value of the green cell ("1") is not shown until I moved the
cursor 9 cells to the left.
In the vertical direction everything is exactly correct. The problem is
the horizontal.
As I found out just a minute ago, the reason seems not to be the method
GeoMouseEvent.getMapCoordinate(.) because if I move the cursor in the
lower left corner, it returns the correct lat/lon position of my raster!
So the problem must be GridCoverage.evaluate(Point2D,.).
Is there a bug in the transformation from the lat/lon to raster
coordinates? Rounding problems?
I am currently using GT2.1.M3 because of some reasons.
Is it a general problem or already fixed in a new GT version?
With kind regards
Martin Schmitz
===========================
Code
===========================
StyledMapPane mapPane; // Map to show the raster
GridCoverage gc; // Raster displayed in MapPane
JLabel rasterValueLabel; // Label showing the raster value
...
mapPane.addMouseMotionListener(new MouseMotionAdapter() {
private void displayRasterValue(MouseEvent e) {
if ( e==null || !(e instanceof GeoMouseEvent) )
return;
// determine the world coordinates of current mouse position
Point2D actPos = ((GeoMouseEvent)e).getMapCoordinate(null);
// determine the grid value(s)
double[] gcValue = new double[0];
String gcValueStr = "";
try {
// determine the grid sample (may throw Exception!)
// at the world coordinates
gcValue = gc.evaluate(actPos, (double[])null);
// store the values of eachs grid band in a string
for (int j=0; j<gcValue.length; j++) {
if (j>0)
gcValueStr += " / ";
gcValueStr += gcValue[j];
}
} catch ( Exception err ) {
// Mouse position out of raster data
}
rasterValueLabel.setText(valueStr);
}
public void mouseMoved(MouseEvent e) {
displayRasterValue(e);
}
public void mouseDragged(MouseEvent e) {
displayRasterValue(e);
}
});
...
===========================
Bernhard Kastner schrieb:
> Martin Desruisseaux wrote:
>
>>> 2. I want to change this behaviour to pan the map. So, when moving
>>> the mouse, the map also moves, but doesn't zoom or anything else. Is
>>> this possible?
>>
>>
>> You can create yours own subclass of StyledMapPane and override the
>> following method:
>>
>> protected void mouseSelectionPerformed(Shape area) {
>> }
>
>
> thanks, I've found it. I think I'll try it by altering the preferredArea
> or the mapPane
>
>>>> And another question: As already mentioned, I'm using the methods as
>>>> in the Spearfish Sample, which uses J2D-renderer. I experienced
>>>> OutOfMemoryExceptions when dealing with larger shapefiles (3x 30
>>>> MB). Is there a possibility to avoid that?
>>>
>>>
>>
>> Technically yes, but it is hard to use at this time.
>>
>> There is some chances that the shapefile datastore stores the
>> geometries as JTS object with arrays of CoordinatePoint. This storage
>> scheme is expensive. You can "compress" them, but with a cost: the
>> lost of the underlying JTS geometries. Explanation:
>>
>> J2D renderer internally stores all geometries as
>> org.geotools.renderer.geom.Geometry objects using an abstract
>> PointArray structure. The point array may be JTS's Coordinate[] array,
>> a plain double[] array, etc. The idea is to switch from the
>> Coordinate[] representation to a float[] representation.
>>
>> We first need to find the underlying Geometry objects. One possible
>> way is to invokes MapPane.getRenderer().getLayers(). Then iterates
>> through those layers and search for "if (layer instanceof
>> RenderedGeometries)". Invokes RenderedGeometries.getGeometry(). You
>> should not have a GeometryCollection (maybe not the only one, the
>> search should continue for other layers).
>>
>> Invoke Geometry.compress(CompressionLevel.DIRECT_AS_FLOATS). If you
>> get an UnmodifiableGeometryException, try to clone the geometry before
>> to compress it.
>>
>> Set the new geometry to the RenderedGeometries layer.
>>
>> Make sure that there is no reference to the original JTS geometry
>> floating around (you may need to checks in a profiler to make sure
>> that their memory is reclaimed).
>
>
> Maybe this is easier to realise with the LiteRenderer?
> Is there btw. any Tutorial showing howto Render Shapefiles with the
> LiteRenderer? I only found Tutorials which rendered manually generated
> FeatureCollections and have no idea how to render Shapefiles with
> LiteRenderer...
>
> Bernhard
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by:
> Power Architecture Resource Center: Free content, downloads, discussions,
> and more. http://solutions.newsforge.com/ibmarch.tmpl
> _______________________________________________
> Geotools-gt2-users mailing list
> Geo...@li...
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>
|