public bool SHPCreateTree(int nDimension, int nMaxDepth, IEnvelope Bounds) { nDimension = 2; psTree = new SHPTree(); if (Bounds == null) { return(false); } /* -------------------------------------------------------------------- */ /* Allocate the tree object */ /* -------------------------------------------------------------------- */ psTree.nMaxDepth = nMaxDepth; psTree.nDimension = nDimension; /* -------------------------------------------------------------------- */ /* If no max depth was defined, try to select a reasonable one */ /* that implies approximately 8 shapes per node. */ /* -------------------------------------------------------------------- */ if (psTree.nMaxDepth == 0 && _nShapeCount > 0) { int nMaxNodeCount = 1; while (nMaxNodeCount * 4 < _nShapeCount) { psTree.nMaxDepth += 1; nMaxNodeCount = nMaxNodeCount * 2; } } /* -------------------------------------------------------------------- */ /* Allocate the root node. */ /* -------------------------------------------------------------------- */ psTree.psRoot = SHPTreeNodeCreate(Bounds); /* -------------------------------------------------------------------- */ /* If we have a file, insert all it's shapes into the tree. */ /* -------------------------------------------------------------------- */ /* * if( hSHP != NULL ) * { * int iShape, nShapeCount; * * SHPGetInfo( hSHP, &nShapeCount, NULL, NULL, NULL ); * * for( iShape = 0; iShape < nShapeCount; iShape++ ) * { * SHPObject *psShape; * * psShape = SHPReadObject( hSHP, iShape ); * SHPTreeAddShapeId( psTree, psShape ); * SHPDestroyObject( psShape ); * } * } */ return(true); }
private void SHPTreeCollectShapeIds(SHPTree hTree, SHPTreeNode psTreeNode, IEnvelope Bounds, //double [] padfBoundsMin, double [] padfBoundsMax, ref int pnShapeCount, ref int pnMaxShapes, List <int> ppanShapeList) { int i; /* -------------------------------------------------------------------- */ /* Does this node overlap the area of interest at all? If not, */ /* return without adding to the list at all. */ /* -------------------------------------------------------------------- */ if (!SHPCheckBoundsOverlap(psTreeNode.Bounds, Bounds)) { return; } /* -------------------------------------------------------------------- */ /* Grow the list to hold the shapes on this node. */ /* -------------------------------------------------------------------- */ /* * if( pnShapeCount + psTreeNode.nShapeCount > pnMaxShapes ) * { * pnMaxShapes = (pnShapeCount + psTreeNode.nShapeCount) * 2 + 20; * ppanShapeList = (int *) * SfRealloc(*ppanShapeList,sizeof(int) * *pnMaxShapes); * } */ /* -------------------------------------------------------------------- */ /* Add the local nodes shapeids to the list. */ /* -------------------------------------------------------------------- */ for (i = 0; i < psTreeNode.nShapeCount; i++) { ppanShapeList.Add(Convert.ToInt32(psTreeNode.panShapeIds[i])); pnShapeCount++; //(*ppanShapeList)[(*pnShapeCount)++] = psTreeNode->panShapeIds[i]; } /* -------------------------------------------------------------------- */ /* Recurse to subnodes if they exist. */ /* -------------------------------------------------------------------- */ for (i = 0; i < psTreeNode.nSubNodes; i++) { if (psTreeNode.apsSubNode[i] != null) { SHPTreeCollectShapeIds(hTree, (SHPTreeNode)psTreeNode.apsSubNode[i], Bounds, ref pnShapeCount, ref pnMaxShapes, ppanShapeList); } } }