I need to perform a polygon on raster cookie-cut and pixel sum using GeoServer. The polygon (GeoJSON) and raster are both in WGS84 (4326). The raster is a very large GeoTIFF population raster published with GeoServer. I have two questions:
How to do the entire operation in GeoServer?
Alternatively, how to query the raw pixel values from the rectangular extent of the polygon (minx, miny, maxx, maxy), and I can do the pixel in/out sum analysis myself.
I have tried WMS queries and WCS queries but cannot find a way to request the raw pixel values rather than a PNG rendered result. I have also tried some WPS sample queries, with no success. I'm not seeing much from Google on polygon-on-raster statistics. Is this entire query possible in GeoServer? Or is at least fetching a rectangular area of raw pixels from the GeoTIFF from GeoServer possible?
Thanks!!
To fetch a rectangle of pixels as a GeoTiff you would need to use a WCS request. The easiest way to define one of those is using the WCS Request generator - for example:
<?xml version="1.0" encoding="UTF-8"?><GetCoverage version="1.0.0" service="WCS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.opengis.net/wcs" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" xsi:schemaLocation="http://www.opengis.net/wcs http://schemas.opengis.net/wcs/1.0.0/getCoverage.xsd">
<sourceCoverage>nurc:Pk50095</sourceCoverage>
<domainSubset>
<spatialSubset>
<gml:Envelope srsName="EPSG:32633">
<gml:pos>347649.93086859107 5176214.082539256</gml:pos>
<gml:pos>370725.976428591 5196961.352859256</gml:pos>
</gml:Envelope>
<gml:Grid dimension="2">
<gml:limits>
<gml:GridEnvelope>
<gml:low>0 0</gml:low>
<gml:high>545 490</gml:high>
</gml:GridEnvelope>
</gml:limits>
<gml:axisName>E</gml:axisName>
<gml:axisName>N</gml:axisName>
</gml:Grid>
</spatialSubset>
</domainSubset>
<output>
<crs>EPSG:32633</crs>
<format>GeoTIFF</format>
</output>
</GetCoverage>
To extract values of a raster bounded by a polygon you can use a WPS request to crop to a polygon and then sum the pixels yourself:
<?xml version="1.0" encoding="UTF-8"?><wps:Execute version="1.0.0" service="WPS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.opengis.net/wps/1.0.0" xmlns:wfs="http://www.opengis.net/wfs" xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" xmlns:wcs="http://www.opengis.net/wcs/1.1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd">
<ows:Identifier>ras:CropCoverage</ows:Identifier>
<wps:DataInputs>
<wps:Input>
<ows:Identifier>coverage</ows:Identifier>
<wps:Reference mimeType="image/tiff" xlink:href="http://geoserver/wcs" method="POST">
<wps:Body>
<wcs:GetCoverage service="WCS" version="1.1.1">
<ows:Identifier>nurc:Pk50095</ows:Identifier>
<wcs:DomainSubset>
<ows:BoundingBox crs="http://www.opengis.net/gml/srs/epsg.xml#32633">
<ows:LowerCorner>347649.93086859107 5176214.082539256</ows:LowerCorner>
<ows:UpperCorner>370725.976428591 5196961.352859256</ows:UpperCorner>
</ows:BoundingBox>
</wcs:DomainSubset>
<wcs:Output format="image/tiff"/>
</wcs:GetCoverage>
</wps:Body>
</wps:Reference>
</wps:Input>
<wps:Input>
<ows:Identifier>cropShape</ows:Identifier>
<wps:Data>
<wps:ComplexData mimeType="application/wkt"><![CDATA[POLYGON((x1 y1, x2 y2,......))]]></wps:ComplexData>
</wps:Data>
</wps:Input>
</wps:DataInputs>
<wps:ResponseForm>
<wps:RawDataOutput mimeType="image/tiff">
<ows:Identifier>result</ows:Identifier>
</wps:RawDataOutput>
</wps:ResponseForm>
</wps:Execute>
Or you could write your own custom process to carry out the whole process in one go.
Related
I am a starter with the Geoserver.
I created lineString vector layer with lineSymbolizer SLD style.
And the vector layer is connected by postgis and that layer only have linestring geometry rowdata. other attributes values does not exist(only linstring coordinates)
grayscaled layer
<?xml version="1.0" encoding="UTF-8"?>
<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">
<!-- a Named Layer is the basic building block of an SLD document -->
<NamedLayer>
<Name>line</Name>
<UserStyle>
<Title>Line</Title>
<Abstract>greyscaled line</Abstract>
<FeatureTypeStyle>
<Rule>
<Name>rule1</Name>
<Title>greyscaled Line</Title>
<Abstract></Abstract>
<LineSymbolizer>
<Stroke>
<CssParameter name="stroke">#000</CssParameter>
<CssParameter name="opacity">0.1</CssParameter>
</Stroke>
</LineSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>
and I want to convert or set this layer greyscaled color to RGB coloring by quantity.
the outputs should be like this image
RGB Colormap
Geoserver RasterSymbolizer
I tried make new SLD using 'RasterSymbolizer Colormap' from geoserver, but I failed..
Is it possible use rasterSymbolizer in linestring vector layer map?
I want to implement a rendering transformation using the NDVI index on grayscale tiff. I am following this link:-
https://docs.geoserver.org/stable/en/user/styling/sld/extensions/rendering-transform.html
What type of data will work for it?
I tried the sld provided in the Geoserver manual, but that doesn't seem to work on my data, but on applying that style, it does not work
<NamedLayer>
<Name>cite:NDVI</Name>
<UserStyle>
<Title>NDVI</Title>
<FeatureTypeStyle>
<Transformation>
<ogc:Function name="ras:Jiffle">
<ogc:Function name="parameter">
<ogc:Literal>GRAY_INDEX</ogc:Literal>
</ogc:Function>
</ogc:Function>
</Transformation>
<Rule>
<RasterSymbolizer>
<Opacity>1.0</Opacity>
<ColorMap>
<ColorMapEntry color="#0000ff" quantity="-0.17"/>
<ColorMapEntry color="#548022" quantity="0.07"/>
<ColorMapEntry color="#f6f7f5" quantity="0.4"/>
</ColorMap>
</RasterSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>
I want my grayscale tiff to be transformed to NDVI band color mapping.
The page you link to shows how to calculate NDVI from a multiband Sentinel image by combining bands 3 and 7, using this formula.
nir = src[7];
vir = src[3];
dest = (nir - vir) / (nir + vir);
Your grayscale image only has one band so it is impossible to calculate NDVI from it.
I need to get width/height of displayed image in imegView and compare it to orginal image size which is in imageView.getImage().getWidth()/getHeight() and listen changes if user resize it form application GUI.
I get this size from imageView.fitWidthProperty() and similar for height, but I get size of imageView not image within it:
I get size of blue which is imageView but I need size of displayed image (green). How can I get it as property to listen when user resize window app (green also change size but it seems to have max and min size so it stop resize with imageView when it is max or min).
I use this property to compute % of size of orginal image in bottom right below blue rectangle.
Is it possible?
E: Below is fxml of this tab:
<BorderPane fx:id="root" fx:controller="..."
xmlns:fx="..." xmlns="..." stylesheets="#...css">
<center>
<StackPane>
<ImageView fx:id="..."/>
<fx:include source="...fxml" fx:id="..."/>
</StackPane>
</center>
<bottom>
<VBox fx:id="..." minHeight="110" styleClass="small-padding" spacing="5">
<HBox alignment="CENTER_RIGHT" spacing="5">
<fx:include source="...fxml" resources="..."
fx:id="..."/>
</HBox>
<TextArea fx:id="..." promptText="%..." styleClass="-fx-description-text-area"/>
</VBox>
</bottom>
When the ImageView is set to preserve the aspect ratio, one has to calculate the real dimensions by hand. At least I've not found another way.
double aspectRatio = image.getWidth() / image.getHeight();
double realWidth = Math.min(imageView.getFitWidth(), imageView.getFitHeight() * aspectRatio);
double realHeight = Math.min(imageView.getFitHeight(), imageView.getFitWidth() / aspectRatio);
To explain this a bit: getFitHeight/Width is your blue rectangle. When preserving the aspect ratio of the source image, at least one side of the blue rectangle must have the same length as the corresponding side of the green rectangle. Also, the green rectangle will always be inside of the blue one, hence the call to Math.min().
~>1)
The fact that the Image is not resizing to cover all the ImageView has to do with preserveRatio method.If you want to be covered setPreserveRatio(false);
with a combination of setSmooth( true );
~>2)
The green border is the size of the original image.
~>3)
Before adding the Image to the ImageView you can do:
Image image = new Image("FILE:...");
image.getWidth( );
image.getHeight( );
And that is the original size of the image.
As for the size of the image when it is displayed inside the ImageView:
imageView.getFitWidth();
imageView.getFitHeight();
For the size of ImageView inside the Scene (the blue border in your question):
imageView.getWidth();
imageView.getHeight();
ImageView class has properties for the above.
I am not aware of any property that you could use directly to get at the numbers you want but you might propose this as an improvement for a future version of JavaFX.
What you can do now is write some code which tracks all proerties of the ImageView which have an influence on the size of the displayed image and then compute the displayed size yourself. This does not sound too complicated to me.
I have a file with three columns. All three have different values. To plot it in a
smooth surface with a color gradient for third column what should I do? First two columns are pseudo randomly distributed. And so do the final column.
The data file looks like this:
8.4295190 0.3860565 0.3706621
-2.9886350 -0.1156874 -0.1314160
8.4375611 0.2617630 0.3710158
8.4092863 0.3195774 0.3697725
8.4237288 0.3930579 0.3704075
-1.1439280 -0.7286996 -0.0919299
-1.0866221 -0.9426172 -0.0873246
-0.9633012 -0.8667140 -0.0774141
-0.8225506 -0.6229306 -0.0661029
-0.9931836 -0.6562048 -0.0798155
-1.3138121 -0.8559578 -0.1055823
-0.8687813 -0.7689202 -0.0698182
7.3637155 1.8145656 0.1891778
7.4434600 1.9952866 0.1912265
7.5885025 1.8936264 0.1949527
7.3067197 1.8313323 0.1877136
7.5324886 2.0066328 0.1935137
You could use dgrid3d to turn your points into grid data:
set dgrid3d 32,32
set xyplane at 0
splot 'data' with pm3d
This creates a grid with 32 rows and 32 columns from your data.
You can increase the number of grid points to get a smoother surface and you may also want to use set pm3d interpolate 0,0, which means that the optimal smoothing is applied to the surface.
I want develop an matlab's application that can show the bounding box to the object in the image.
I have detected the object, and cropped it.
And now, for the boundng box, i just have to add 10 in all my pixel.
For exmpl:
x=x+10;
y=y+10;
w=w+10;
h=h+10;
I use imcrop function.
But the problem is that i dont understand how to get the pixel's coordinates from imcrop.
[I_crop, I_rect]=imcrop(ImSeq(:,:,1),[])
I_rect=floor(I_rect);
final_rect=I_rect;
for t=1:NumImages
cur_r=final_rect(2);
cur_c=final_rect(1);
for r= cur_r -10:cur_r+10
for c=cur_c-10:cur_c+10
temp= abs(I_crop-ImSeq(r:r+I_rect(4),c:c+I_rect(3),t));
what is final_rect(2), final_rect(1), I_rect(4) and I_rect(3)?
How i can get the coordinates of x,y,w,h of the cropped image??
Thanks
In [I2 rect] = imcrop(I), rect is the cropping rectangle, a four-element position vector. Within the original image, the cropped area is defined by:
rect(2) the current row
rect(1) the current column
rect(3) is the width
rect(4) the height.