private static int MaxPolyfillSize(List <GeoCoord> coords, int resolution) { var h3Coords = FromGeoCoords(coords); int nbIndex = 0; H3GeoPolygon polygon = new H3GeoPolygon(); polygon.geofence = new H3GeoFence(); GCHandle arrHandle = GCHandle.Alloc(h3Coords.ToArray(), GCHandleType.Pinned); try { polygon.geofence.verts = arrHandle.AddrOfPinnedObject(); polygon.geofence.numVerts = h3Coords.Length; polygon.numHoles = 0; polygon.holes = IntPtr.Zero; nbIndex = maxPolyfillSize(ref polygon, resolution); } finally { arrHandle.Free(); } return(nbIndex); }
public static ulong[] Polyfill(List <GeoCoord> coords, int resolution) { ulong[] index = null; int nbIndex = MaxPolyfillSize(coords, resolution); var h3Coords = FromGeoCoords(coords); H3GeoPolygon polygon = new H3GeoPolygon(); polygon.geofence = new H3GeoFence(); GCHandle arrHandle = GCHandle.Alloc(h3Coords.ToArray(), GCHandleType.Pinned); List <ulong> validIndexes = new List <ulong>(); try { polygon.geofence.verts = arrHandle.AddrOfPinnedObject(); polygon.geofence.numVerts = h3Coords.Length; polygon.numHoles = 0; polygon.holes = IntPtr.Zero; index = new ulong[nbIndex + 1]; Console.Write("{0}", nbIndex); polyfill(ref polygon, resolution, index); for (int i = 0; i < index.Length; i++) { if (index[i] != 0) { validIndexes.Add(index[i]); } } Console.WriteLine(" --> {0}", validIndexes.Count); } finally { arrHandle.Free(); } return(validIndexes.ToArray()); }
private static extern int maxPolyfillSize(ref H3GeoPolygon polygon, int res);
private static extern void polyfill(ref H3GeoPolygon polygon, int res, ulong[] index);