⚠️ Our 0.1 release refactored several early-development functions for long-term stability, to update your code see here. ⚠️
Future changes will come with deprecation warnings! 🙂

Raster to points

Raster to points#

This example demonstrates the conversion of a raster to point vector using geoutils.Raster.to_points().

We open a raster.

import geoutils as gu

filename_rast = gu.examples.get_path("exploradores_aster_dem")
rast = gu.Raster(filename_rast)
rast.crop([rast.bounds.left, rast.bounds.bottom, rast.bounds.left + 500, rast.bounds.bottom + 500])
Raster(
  data=[[2787.60595703125 2791.827392578125 2796.588623046875 2802.831298828125
         2809.177734375 2814.274658203125 2818.896484375 2823.46484375
         2827.637451171875 2831.105712890625 2834.459228515625 2837.686279296875
         2841.211669921875 2844.62060546875 2848.480224609375 2853.62744140625
         2858.103271484375]
        [2790.041748046875 2794.14306640625 2797.886962890625 2802.295654296875
         2807.56982421875 2812.60693359375 2817.2060546875 2821.789306640625
         2826.025634765625 2829.4169921875 2832.493408203125 2835.345947265625
         2838.636474609375 2841.8671875 2845.163330078125 2849.126953125
         2852.74951171875]
        [2790.01318359375 2794.48046875 2798.052978515625 2801.71337890625
         2806.081298828125 2810.831787109375 2815.83740234375 2820.44189453125
         2823.876708984375 2826.3056640625 2828.75732421875 2831.74169921875
         2835.902099609375 2839.8056640625 2842.990966796875 2845.685302734375
         2848.302978515625]
        [2787.404296875 2793.198486328125 2796.791259765625 2800.179443359375
         2803.896240234375 2808.101318359375 2813.46435546875 2818.518798828125
         2821.96044921875 2823.79345703125 2825.06494140625 2826.948974609375
         2830.43701171875 2835.113525390625 2839.63427734375 2842.345703125
         2844.58935546875]
        [2780.802734375 2788.757568359375 2793.22509765625 2796.52197265625
         2799.50390625 2802.563720703125 2807.08203125 2812.93310546875
         2818.09716796875 2820.744140625 2822.229736328125 2823.191162109375
         2824.41162109375 2827.488037109375 2832.147705078125 2835.232421875
         2838.1435546875]
        [2773.79443359375 2782.43798828125 2788.442138671875 2792.0859375
         2794.5048828125 2796.739013671875 2799.25146484375 2804.08349609375
         2809.9111328125 2813.944091796875 2817.44091796875 2819.73876953125
         2820.715087890625 2822.190673828125 2823.980224609375 2825.81103515625
         2828.900146484375]
        [2766.432861328125 2774.9248046875 2782.713134765625 2787.294677734375
         2790.200439453125 2792.547607421875 2794.365966796875 2797.501220703125
         2801.781494140625 2805.190185546875 2809.259521484375 2814.107666015625
         2817.0615234375 2818.98974609375 2820.21826171875 2821.405517578125
         2823.73388671875]
        [2760.042236328125 2766.990478515625 2775.755859375 2781.633544921875
         2785.21923828125 2787.9775390625 2790.28369140625 2793.221435546875
         2796.7421875 2799.369140625 2801.563720703125 2805.430908203125
         2810.263427734375 2815.006591796875 2817.646240234375 2819.2177734375
         2821.1279296875]
        [2754.795654296875 2760.5390625 2768.49169921875 2775.6904296875
         2780.48876953125 2783.1533203125 2785.264892578125 2787.925537109375
         2791.50244140625 2794.831298828125 2796.56787109375 2798.9208984375
         2803.139404296875 2809.09912109375 2813.513671875 2816.24072265625
         2818.427734375]
        [2747.34423828125 2753.971923828125 2759.97607421875 2768.08642578125
         2775.585693359375 2779.11962890625 2780.95556640625 2782.66943359375
         2785.430419921875 2789.6669921875 2793.075927734375 2795.703125
         2799.1435546875 2803.7431640625 2808.182861328125 2811.646728515625
         2814.320556640625]
        [2730.134033203125 2742.407958984375 2749.86083984375 2757.119873046875
         2766.955322265625 2773.724609375 2776.672607421875 2778.48974609375
         2780.53466796875 2783.794921875 2788.5283203125 2793.44873046875
         2797.675048828125 2801.619873046875 2805.047119140625 2807.77490234375
         2810.013671875]
        [2708.699462890625 2723.0771484375 2735.676513671875 2744.12451171875
         2752.847900390625 2762.31591796875 2768.998779296875 2772.91943359375
         2775.842041015625 2778.345703125 2782.7041015625 2789.482666015625
         2795.76171875 2799.666015625 2802.486572265625 2804.822509765625
         2807.17041015625]
        [2697.2666015625 2706.491943359375 2717.402099609375 2727.287109375
         2736.778076171875 2746.714111328125 2755.538330078125 2762.216552734375
         2768.456787109375 2772.765380859375 2776.817626953125 2781.47802734375
         2787.206298828125 2791.65771484375 2796.071044921875 2800.388916015625
         2803.46044921875]
        [2692.988037109375 2699.080810546875 2705.918701171875 2712.4384765625
         2721.26708984375 2732.938232421875 2743.584228515625 2751.74072265625
         2760.072021484375 2766.972412109375 2772.3681640625 2775.621826171875
         2778.958740234375 2782.458740234375 2787.37744140625 2792.550537109375
         2795.291748046875]
        [2690.725830078125 2695.724609375 2700.945556640625 2706.21484375
         2711.6953125 2720.744384765625 2732.626708984375 2742.75830078125
         2752.4287109375 2761.390380859375 2768.9580078125 2772.854248046875
         2775.531005859375 2778.1357421875 2781.721435546875 2785.487548828125
         2787.7939453125]
        [2688.682373046875 2693.766845703125 2697.1826171875 2701.110107421875
         2705.33642578125 2710.96337890625 2718.26220703125 2726.223876953125
         2738.56103515625 2752.47802734375 2763.214111328125 2768.239501953125
         2770.820068359375 2773.453857421875 2776.59130859375 2780.051025390625
         2783.099609375]
        [2686.294677734375 2692.3466796875 2694.712890625 2696.897705078125
         2700.072509765625 2703.650390625 2706.4169921875 2708.90478515625
         2717.23388671875 2734.168701171875 2752.940673828125 2762.720947265625
         2765.868408203125 2768.098388671875 2770.859375 2773.97216796875
         2777.3623046875]]
  transform=| 30.00, 0.00, 627175.00|
            | 0.00,-30.00, 4834055.00|
            | 0.00, 0.00, 1.00|
  crs=EPSG:32718
  nodata=-9999.0)


Let’s plot the raster.

rast.plot(cmap="terrain")
topoints

We convert the raster to points. By default, this returns a vector with column geometry burned.

Vector(
  ds=                 b1                        geometry
       0       1271.392456  POINT (627175.000 4852085.000)
       1       1275.370850  POINT (627205.000 4852085.000)
       2       1250.194092  POINT (627235.000 4852085.000)
       3       1199.716797  POINT (627265.000 4852085.000)
       4       1182.209839  POINT (627295.000 4852085.000)
       ...             ...                             ...
       324189  1373.992676  POINT (643195.000 4833575.000)
       324190  1394.760132  POINT (643225.000 4833575.000)
       324191  1413.984985  POINT (643255.000 4833575.000)
       324192  1437.386841  POINT (643285.000 4833575.000)
       324193  1461.232178  POINT (643315.000 4833575.000)

       [324194 rows x 2 columns]
  crs=PROJCS["WGS 84 / UTM zone 18S",GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",-75],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",10000000],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","32718"]]
  bounds=BoundingBox(left=627175.0, bottom=4833575.0, right=643315.0, top=4852085.0))


We plot the point vector.

pts_rast.plot(ax="new", column="b1", cmap="terrain", legend=True)
topoints

Total running time of the script: (0 minutes 21.885 seconds)

Gallery generated by Sphinx-Gallery