GalElement* shp2gal(Shapefile::Main& main, int criteria, bool save, double precision_threshold) { using namespace Shapefile; GalElement * full; //ReadOffsets(fname); //ReadBoxes(fname); gRecords = main.records.size(); double shp_min_x = (double)main.header.bbox_x_min; double shp_max_x = (double)main.header.bbox_x_max; double shp_min_y = (double)main.header.bbox_y_min; double shp_max_y = (double)main.header.bbox_y_max; double shp_x_len = shp_max_x - shp_min_x; double shp_y_len = shp_max_y - shp_min_y; long gx, gy, cnt, total=0; gx= gRecords / 8 + 2; gMinX.alloc(gRecords, gx, shp_x_len ); gMaxX.alloc(gRecords, gx, shp_x_len ); for (cnt= 0; cnt < gRecords; ++cnt) { PolygonContents* ply = dynamic_cast<PolygonContents*> ( main.records[cnt].contents_p); gMinX.include( cnt, ply->box[0] - shp_min_x ); gMaxX.include( cnt, ply->box[2] - shp_min_x ); } gy= (int)(sqrt((long double)gRecords) + 2); do { gY= new PartitionM(gRecords, gy, shp_y_len ); for (cnt= 0; cnt < gRecords; ++cnt) { PolygonContents* ply = dynamic_cast<PolygonContents*> ( main.records[cnt].contents_p); gY->initIx( cnt, ply->box[1] - shp_min_y, ply->box[3] - shp_min_y ); } total= gY->Sum(); if (total > gRecords * 8) { delete gY; gy = gy/2 + 1; total= 0; } } while ( total == 0); GalElement * gl= MakeContiguity(main, criteria, precision_threshold); if (gY) delete gY; gY = 0; if (gOffset) delete [] gOffset; gOffset = 0; if (gBox) delete [] gBox; gBox = 0; full = MakeFull(gl); if (gl) delete [] gl; gl = 0; return full; }
/* PolygonPartition */ void PolygonPartition::MakeSmallPartition(const int mX, const double Start, const double Stop) { pX.alloc(NumPoints, mX, Stop-Start); for (int cnt= 0; cnt < NumPoints; ++cnt) { Shapefile::Point* pt= GetPoint(cnt); if (pt->x >= Start && pt->x <= Stop) pX.include(cnt, pt->x - Start); } MakeNeighbors(); }
/* PolygonPartition */ int PolygonPartition::MakePartition(int mX, int mY) { if (mX == 0) mX = NumPoints/4 + 2; if (mY == 0) mY = (int)(sqrt((long double)NumPoints) + 2); pX.alloc(NumPoints, mX, GetMaxX() - GetMinX());// bBox._max().x - bBox._min().x); pY.alloc(NumPoints, mY, GetMaxY() - GetMinY());//bBox._max().y - bBox._min().y); double xStart= GetMinX(), yStart= GetMinY(); for (int cnt= 0; cnt < NumPoints; ++cnt) { pX.include(cnt, GetPoint(cnt)->x - xStart); pY.initIx(cnt, GetPoint(cnt)->y - yStart); }; MakeNeighbors(); return 0; }