0

I am trying to extract the values associated to each pixel in a tiff image using the gdal library.

 # Create a polygon from the pixel coordinates
            polygon = Polygon([(x_min, y_min), (x_min, y_max), (x_max, y_max), (x_max, y_min)])

 # Associate the polygon with the value
            polygon.value = value

When I try to access the value of the polygon I got the error

AttributeError: 'Polygon' object has no attribute 'value'

3
  • Please provide a Minimal, Reproducible Example. What is Polygon? Commented Jun 7, 2023 at 11:13
  • 1
    Please edit the question and put all relevant information into this instead of writing a new comment. But it is still unclear where this value attribute come from!? Commented Jun 7, 2023 at 17:18
  • I imported the polygon object from the shapely.geometry library. It is supposed to represent the shape of the field that I wnt to extract. Commented Jun 8, 2023 at 10:54

1 Answer 1

0

After many tries, I discovered that the polygon object do not really have the value attribute ( it only have two attributes : 'exterior' which is the ring which bounds the positive space of the polygon and 'interiors' which is a sequence of rings which bound all existing holes.), so I decided to change the logic that I am working with.

polygon = Polygon([(x, y), (x+1, y), (x+1, y+1), (x, y+1)])
value = int(array[y, x])  # Convert pixel value to int

This code works perfectly well for my use case.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.