How to convert many polygons to a bitmap

How to take a set of polygons that contain arbitrary values, and create a corresponding bitmap image, where each pixel contains a polygon value in this place?

To put the question in context, my polygons contain information about the average number of people per square kilometer in the polygon. I need to create a bitmap / bitmap that contains pixels representing the population in 200 meter boxes.

In the past, I did something similar when I used a polygon to create a mask, drawing in raster and fill values, and then converting the bitmap into an array that I can manipulate. I am sure there is a better way to do this!

I clarify the question a little on request.

  • There are several polygons, each polygon is a set of vectors
  • Each polygon will have a unique value.
  • Polygons do not overlap

thank

Nick

+3
source share
5 answers

@Nick R

I originally used ArcGIS 9.2, but this does not work with C # and 64-bit, so I now use GDAL ( http://www.gdal.org ).

Does gdal_rasterize not do exactly what you want?

+1
source

What GIS software do you use? ArcGIS offers the Polygon to Raster tool in ArcGIS 9.2 or later, which is scriptable as a function of PolygonToRaster_conversion.

PolygonToRaster_conversion (in_features, value_field, out_raster_dataset, cell_assignment, priority_field, cellsize)
+2
source

, , , , (, , ), , . , , .

. ?

  • ( , ) <
  • , ?
  • , , <

-Adam

+2

. , , :

 have a NY * 2 array of x positions: int x[NY][2]
foreach polygon
  clear the array to -1
  for each edge line
    foreach horizontal raster line iy intersecting the line
      generate ix, the x position where the raster intersects the line
      if x[iy][0] == -1, set it to ix, else set x[iy][1] to ix
    end foreach iy
  end foreach edge
  foreach iy
    fill the pixels between x[iy][0] and x[iy][1] with the polygons label
  end foreach iy
end foreach polygon

, , , , , . .

, , , A B A, . - , 2 , - 2 , 4 .

If the polygons are NOT convex, this is a little different. Wherever the edge crosses the raster line, switch all the pixels from there to some randomly chosen X coordinate, such as the left edge of the β€œscreen”. When you finish all the edges, only the internal pixels will switch an odd number of times.

+2
source

ImageMagick can convert from svg to png, maybe you can take a look at the code or just create svg and use IM to convert? Scruffy does it.

+1
source

Source: https://habr.com/ru/post/1696831/


All Articles