Hexagon Geospatial
MENU

Spatial Modeler

Discuss topics with other Hexagon Geospatial Product pioneers and experts to get the most out of our products.
Showing results for 
Search instead for 
Do you mean 
Reply
Technical Evangelist
Posts: 665
Registered: ‎10-01-2015

Re: How to build a generalized raster with lower resolution than the input raster?

Hi Marisa,

 

I'm not entirely following your screenshots. Can you either zip up and attach the point shapefile to this thread, or email it to me via the email address I sent you via PM.

 

Cheers

 

Ian Anderson
Chief Product Owner, Desktop Remote Sensing
Hexagon Geospatial
Technical Evangelist
Posts: 665
Registered: ‎10-01-2015

Re: How to build a generalized raster with lower resolution than the input raster?

[ Edited ]

Thanks for sending me the points Marisa.

 

First up - you hadn't mentioned that your data is in Lat/Lon as opposed to being in a projected coordinate system (PCS) such as UTM. So the data isn't using linear units (it's using decimal degrees). So it's worthwhile pointing out that wherever you are then trying to specify a linear measurement (such as 1m x 1m pixels, or 20m x 20m pixels) those will be being translated back into an approximate dd value. It shouldn't adversely affect the results much - but you need to be aware that mixing linear and non-linear units has repercussions. You may want to considered reprojecting the points to a PCS first, such as UTM.

 

Anyway, I took your Lat/Lon points and converted them to a sparse raster dataset using this model:

rasterize.PNG

 

I then took the rasterized points (buildings_rasterized.img) and used it as input to the model I provided earlier in this thread. 

 

Here's the resulting (approximately 20m x 20m pixel) Sum raster with the original points overlaid (and color coded by the residents attributes). I also color-coded the raster pixels to make it look nicer:

 

result1.png

 

And here's a zoomed-in version showing the InquireCursor reporting a value of 11 for a pixel containing two points with 5 and 6 residents each. Looks correct.

 

result2.PNG

 

 

So, I'm not sure why you're getting a different result in the screenshots you provided, Everything looks good to me. It may be because you are using the old (legacy) "Vector as Raster" operator, whereas I used the modern Features-based operators. Could also be a problem with older software - I'm using ERDAS IMAGINE 2018. I didn't try again with ERDAS IMAGINE 2016 v16.1, but my previous test indicate I should get similar results there as well. You said you were using vanilla ERDAS IMAGINE 2016 (as opposed to v16.1 / build 650)?

 

Probably worth trying the conversion to raster using the new Features operators and if that doesn't work you may need to upgrade to ERDAS IMAGINE 2018.

 

Cheers

 

 

Ian Anderson
Chief Product Owner, Desktop Remote Sensing
Hexagon Geospatial
Frequent Contributor
Posts: 83
Registered: ‎07-17-2017

Re: How to build a generalized raster with lower resolution than the input raster?

Hi Ian,

 

your results are 100% what I was looking for! Thanks a bunch for spending so much time on helping me.

I couldn't find out the exact name of the ERDAS Imagine version that I'm using yesterday  but finally found the installation file where it is written in the name. And shame on me it's v16.0... :-( And sorry for not mentioning the CRS...

Changing the conversion operator didn't help neither but probably this isn't the point as long as I'm using an old version.

 

How does it happen that there is such a huge difference in the results you get using the same operators and property values in two different versions and they don't behave the same way? 

 

I tried to build your workflow as recipe in spatial workshop in M.App Studio but it fails while running. I guess it's because of the Matrix Operator. It looks like there are parts missing when I copy the value which is shown in the properties in ERDAS Imagine and I have no idea how to create it.

Do you have a last hint for me how to solve this?

 

Thanks a lot

Marisa

Frequent Contributor
Posts: 83
Registered: ‎07-17-2017

Re: How to build a generalized raster with lower resolution than the input raster?

Hi Ian,

 

I was so much into building recipes on the platform that I forget about the possibility to upload spatial models.

So now the model runs on the platform and the results are as expected! Great, thanks again.

 

But still my question is how the matrix operator works. How can I create a custom matrix as you did in this model?

E.g. if I want to change the generalized cell size to 40x40 I guess I have to modify the matrix operator right?

I already had a look at other posts but couldn't find a solution. maybe it's a stupid question...

 

Thanks

Marisa

Technical Evangelist
Posts: 665
Registered: ‎10-01-2015

Re: How to build a generalized raster with lower resolution than the input raster?

[ Edited ]

Hi Marisa,

 

Glad you found the Upload option! Makes life much easier if you develop (and test) the model in ERDAS IMAGINE and then upload it to Smart M.App (or APOLLO) afterwards. 

 

With regard to the Matrix / Kernel / Focus - I'm not sure how you edit them in Spatial Workshop. But in Spatial Modeler you'd simply open up the Custom Matrix Input operator (by double-clicking on it to start the gui provider):

 

matrix.PNG

 

In this editor you can quickly change the size of the matrix via the Width and Height fields.

 

Now - remember I said I hated even-numbered moving windows. Here's why. Moving windows work by centering on the pixel being processed and looking at the surrounding pixels masked by the remainder of the matrix. Easy if the matrix has odd dimensions (e.g. 3x3). But if you have an even number there's no "center pixel". So the window that is considered  is effectively half a pixel "shifted" from the output pixel location. Normally this doens't matter - you asked for an even numbered window and that's the cost of doing so. It's the nature of raster processing.

 

But you wanted an exact "downsampling" from 1m pixels to 20m pixels. In order to get an exact output 20m pixel that lined up with 20 x 20 input 1m pixels (to the exact edge) I had to increase the matrix by 1 and fill the last row and column with zeros. I.e. a 21 x 21 matrix. And set the Define Processing Area parameters the way I did. 

 

So if you want to modify the model to downsample to 40m pixels, you will need to enter Width 41 and Height 41 and hit return.

 

This will set the CellArray to show a matrix that's 41 x 41 cells.

 

Make sure no rows or columns are selected (which effectively means all are considered selected). Change Set Selection to 1 and click From Below. The entire matrix should now be set to 1s.

 

Scroll to the last row and column. Select the last column. Change Set Selection to 0 and click From Below. The last column should now be set to 0s.

 

Unselect the column. Select the last row. Click From Below. The last column should now be set to 0s.

 

Or you can type values directly into cells in the CellArray, but that would be time consuming for a 41 x 41 matrix.

 

That's the matrix defined. Click OK to exit the dialog.

 

Don't forget to change the pixel size on the Define Processing Area to match the matrix footprint e.g. 40m x 40m. 

 

That's it.

 

Cheers

 

Ian Anderson
Chief Product Owner, Desktop Remote Sensing
Hexagon Geospatial
Frequent Contributor
Posts: 153
Registered: ‎10-27-2015

Re: How to build a generalized raster with lower resolution than the input raster?

>So the window that is considered  is effectively half a pixel "shifted" from the output pixel location

 

I think this is a nature of Erdas Imagine in generally. Imagine defines coordinates by the center of the corner pixel. Some other tools use corner of the corner pixel. This leads to troubles when you need to define file to follow for example certain mapsheet. WIth this difference you easily end up having one extra row and column in the output files that happens pretty often.

 

Slightly off topic but still good to be aware.

Frequent Contributor
Posts: 83
Registered: ‎07-17-2017

Re: How to build a generalized raster with lower resolution than the input raster?

Great Ian! It works. :-)

In spatial workshop you are not able to generate a matrix. You need to know the String representation to insert a value.

And thanks for the additional information Timo!

 

This was great support!

 

Cheers 

Marisa

 

Highlighted
Technical Evangelist
Posts: 665
Registered: ‎10-01-2015

Re: How to build a generalized raster with lower resolution than the input raster?

I finally had time to write up a Spatial Recipe for this with an improved Spatial Model. See the write-up here:

 

https://community.hexagongeospatial.com/t5/Spatial-Recipes/Raster-Generalization-Degrade-Downsample-...

 

Cheers

 

Ian Anderson
Chief Product Owner, Desktop Remote Sensing
Hexagon Geospatial
Polls
Please register to vote
Do you need immediate support?
If you encounter a critical issue and need immediate assistance please submit a Service Request through our Support Portal.