brycefrank / pyfor

Tools for analyzing aerial point clouds of forest data.
MIT License
93 stars 19 forks source link

Detected segments misprojected #37

Closed rmanzano-dev closed 5 years ago

rmanzano-dev commented 5 years ago

Hello! I am getting a warning saying this: "This behavior has changed from < 0.3.1, points are now binned from the top left of the point cloud instead of the bottom right to cohere with arrays produced later". And my Shapefile result is not located in the place it should be while the projection set to it is correct. Do you know any solution to this?

Thanks for your help!

brycefrank commented 5 years ago

The warning is a little annoying, but it will go away with 0.3.3 in a month or two., I don't think this is your issue.

Could you describe what you are doing a bit more? It sounds like you are trying to do segmentation? Some reproducible code will help (there is a testing las file in the test suite).

rmanzano-dev commented 5 years ago

I've tested with the old version of pyfor (0.2) and it works well. This is the piece of code which does the segmentation, but the segmentation done is not located properly. The problem comes with the tmp_SHAPE.shp file.

pc = pyfor.cloud.Cloud(init_file) 
chm = pc.chm(1, interp_method = "nearest", pit_filter="median")
segmentation = chm.watershed_seg(min_distance=2, threshold_abs=2, classify=True)
final_segments = segmentation.segments[segmentation.segments["raster_val"] > 0]
df= geopandas.GeoDataFrame(final_segments, geometry= 'geometry')
df.crs="+proj=utm +zone=18 +south +datum=WGS84 +units=m +no_defs +ellps=WGS84"
df.to_file(directory +'/tmp_SHAPE.shp')
brycefrank commented 5 years ago

Thank you for the information. I will look into this today.

One thing to try is setting the .crs attribute of pc to your projection string used in your 6th line before your do any processing

pc = pyfor.cloud.Cloud(init_file)
pc.crs = "+proj=utm +zone..."
#etc
rmanzano-dev commented 5 years ago

I've tried that last thing and I have the same result. For more information I can say that, when I open the result shapefile in ArcGIS, the projection which appears is correct, however, the correct extent should be this one (generated with pyfor 0.2) image and I obtain this one with pyfor 0.3: image

The code only changes by deleting the .segments attribute.

brycefrank commented 5 years ago

This gives me an idea. I should (actually) have time for this today.

brycefrank commented 5 years ago

Turned out to be a quick fix. I must have forgotten to change this hardcoded argument to ._affine

https://github.com/brycefrank/pyfor/blob/20e65932994eb6fa209ac3a2d031d9bca543b04d/pyfor/rasterizer.py#L384-L386

Here is the test set using your code from above:

image

I pushed directly to master. Please update and verify using the "Updating" section of the README.

rmanzano-dev commented 5 years ago

Thank you for your help I will test it on my dataset on Monday and I will confirm you that everything is ok!