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); } } }
private void write(System.IO.StreamWriter sw, SHPTreeNode node, int level) { sw.WriteLine("\n\n\n" + (_nodenr++).ToString() + " node (level=" + level.ToString() + ")"); sw.WriteLine(node.Bounds.minx.ToString() + "\t" + node.Bounds.miny.ToString() + "\t" + node.Bounds.maxx.ToString() + "\t" + node.Bounds.maxy.ToString()); foreach (object obj in node.panShapeIds) { sw.Write(obj.ToString() + ", "); } foreach (SHPTreeNode n in node.apsSubNode) { write(sw, n, level + 1); } }
private SHPTreeNode SHPTreeNodeCreate(IEnvelope env) { SHPTreeNode psTreeNode = new SHPTreeNode(); //psTreeNode.nShapeCount = 0; //psTreeNode.panShapeIds = null; //psTreeNode.papsShapeObj = null; //psTreeNode.nSubNodes = 0; psTreeNode.Bounds = new Envelope(env); //memcpy(psTreeNode.adfBoundsMin,padfBoundsMin,4); //memcpy(psTreeNode.adfBoundsMax,padfBoundsMax,4); return(psTreeNode); }
private void writeSIXNode(BinaryWriter bw, SHPTreeNode node) { // BoundingBox bw.Write((double)node.Bounds.minx); bw.Write((double)node.Bounds.miny); bw.Write((double)node.Bounds.maxx); bw.Write((double)node.Bounds.maxy); // IDs bw.Write((System.Int32)node.panShapeIds.Count); for (int i = 0; i < node.panShapeIds.Count; i++) { bw.Write((System.Int32)node.panShapeIds[i]); } // Subnodes bw.Write((System.Int16)node.apsSubNode.Count); for (int i = 0; i < node.apsSubNode.Count; i++) { writeSIXNode(bw, (SHPTreeNode)node.apsSubNode[i]); } }
private void DestroyEmptyNodes(SHPTreeNode node, int nimIDsPerNode) { }
private bool SHPTreeNodeAddShapeId(SHPTreeNode psTreeNode, SHPObject psObject, int nMaxDepth, int nDimension) { int i; /* -------------------------------------------------------------------- */ /* If there are subnodes, then consider wiether this object */ /* will fit in them. */ /* -------------------------------------------------------------------- */ if (nMaxDepth > 1 && psTreeNode.nSubNodes > 0) { for (i = 0; i < psTreeNode.nSubNodes; i++) { if (SHPCheckObjectContained(psObject, ((SHPTreeNode)psTreeNode.apsSubNode[i]).Bounds)) { return(SHPTreeNodeAddShapeId((SHPTreeNode)psTreeNode.apsSubNode[i], psObject, nMaxDepth - 1, nDimension)); } } } else if (nMaxDepth > 1 && psTreeNode.nSubNodes == 0) { //double [] adfBoundsMinH1=new double[4], adfBoundsMaxH1=new double[4]; //double [] adfBoundsMinH2=new double[4], adfBoundsMaxH2=new double[4]; // double [] adfBoundsMin1=new double[4], adfBoundsMax1=new double[4]; // double [] adfBoundsMin2=new double[4], adfBoundsMax2=new double[4]; // double [] adfBoundsMin3=new double[4], adfBoundsMax3=new double[4]; // double [] adfBoundsMin4=new double[4], adfBoundsMax4=new double[4]; IEnvelope BoundsH1, BoundsH2, Bounds1, Bounds2, Bounds3, Bounds4; SHPTreeSplitBounds(psTreeNode.Bounds, out BoundsH1, out BoundsH2); SHPTreeSplitBounds(BoundsH1, out Bounds1, out Bounds2); SHPTreeSplitBounds(BoundsH2, out Bounds3, out Bounds4); bool b1 = false, b2 = false, b3 = false, b4 = false; if ((b1 = SHPCheckObjectContained(psObject, Bounds1)) || (b2 = SHPCheckObjectContained(psObject, Bounds2)) || (b3 = SHPCheckObjectContained(psObject, Bounds3)) || (b4 = SHPCheckObjectContained(psObject, Bounds4))) { //psTreeNode->nSubNodes = 4; //psTreeNode.apsSubNode.Clear(); psTreeNode.apsSubNode.Add(SHPTreeNodeCreate(Bounds1)); psTreeNode.apsSubNode.Add(SHPTreeNodeCreate(Bounds2)); psTreeNode.apsSubNode.Add(SHPTreeNodeCreate(Bounds3)); psTreeNode.apsSubNode.Add(SHPTreeNodeCreate(Bounds4)); /* recurse back on this node now that it has subnodes */ return(SHPTreeNodeAddShapeId(psTreeNode, psObject, nMaxDepth, nDimension)); } } /* -------------------------------------------------------------------- */ /* Otherwise, consider creating two subnodes if could fit into */ /* them, and adding to the appropriate subnode. */ /* -------------------------------------------------------------------- */ else if (nMaxDepth > 1 && psTreeNode.nSubNodes == 0) { //double [] adfBoundsMin1=new double[4], adfBoundsMax1=new double[4]; //double [] adfBoundsMin2=new double[4], adfBoundsMax2=new double[4]; IEnvelope Bounds1, Bounds2; SHPTreeSplitBounds(psTreeNode.Bounds, out Bounds1, out Bounds2); if (SHPCheckObjectContained(psObject, Bounds1)) { //psTreeNode.nSubNodes = 2; psTreeNode.apsSubNode.Clear(); psTreeNode.apsSubNode.Add(SHPTreeNodeCreate(Bounds1)); psTreeNode.apsSubNode.Add(SHPTreeNodeCreate(Bounds2)); return(SHPTreeNodeAddShapeId((SHPTreeNode)psTreeNode.apsSubNode[0], psObject, nMaxDepth - 1, nDimension)); } else if (SHPCheckObjectContained(psObject, Bounds2)) { //psTreeNode.nSubNodes = 2; psTreeNode.apsSubNode.Clear(); psTreeNode.apsSubNode.Add(SHPTreeNodeCreate(Bounds1)); psTreeNode.apsSubNode.Add(SHPTreeNodeCreate(Bounds2)); return(SHPTreeNodeAddShapeId((SHPTreeNode)psTreeNode.apsSubNode[1], psObject, nMaxDepth - 1, nDimension)); } } /* -------------------------------------------------------------------- */ /* If none of that worked, just add it to this nodes list. */ /* -------------------------------------------------------------------- */ psTreeNode.panShapeIds.Add(psObject.ID); return(true); }