阅读:2338回复:8
[求助]如何实现由线生成面??
我想请教大伙一个问题,当我用一条线将一个多边形切割后(比如被分成两分),那么我如何只让它显示一个被切割后的多边形?
|
|
1楼#
发布于:2003-08-18 11:10
你可以看看本版面的那个多边形切割的贴
|
|
2楼#
发布于:2003-08-18 11:24
让斑竹见笑了,那个贴子我是看过的。我的意思是说,我先是用线画(比如在矩形区域画),那么它在边界处要与之相闭合,这时我能不能将由线和边界所组成的闭合区域存储为一个Shape文件呢?
|
|
3楼#
发布于:2003-08-18 11:39
我理解你的意思还是:用线分割一个面,那个分割程序基本能实现,,关于你说的存储为另一个shape文件,能啊,定义一个数据集来保存你的对象,保存为一个shp文件就行。
|
|
4楼#
发布于:2003-09-04 09:55
楼上的兄弟,你所指的“对所有交叉线进行切割,生成一个完全没有交叉的线段集
”是怎么回事呀?那该怎么处理那个交叉点呢? 兄弟懂得不是很多,请见谅! |
|
5楼#
发布于:2003-09-08 13:26
kentcoon所说,个人感觉过于复杂,在mo中不必那么复杂吧?wavvylia用你说的意思是否类似多边形切割?用一个多边形去剪裁一个图层?
|
|
6楼#
发布于:2003-09-08 15:35
也不尽然,我是用等值线生成等值面的,线我倒是能画出来,可下面我就不知道该怎么做了,有个朋友倒是给我提供了一个算法,但是用PB写的,看了几遍,没看懂,不知那个兄弟给帮忙看一下?
附上代码:(注:此代码源自一个姓李的网友。) 1.初始化: oleobject lycur oleobject bandrec,bandline,contourrec dcshp = Create OleObject lycur = Create oleobject dcshp.ConnectTONewObject("MapObjects2.DataConnection") shppath = "D:\my work\polyline2polygon\air" dcshp.Database = shppath If not dcshp.Connect then MessageBox ("错误信息","图形数据库连接失败,请检查") return end if lycur.connecttonewobject("mapobjects2.maplayer") lycur.GeoDataset = dcshp.FindGeoDataset("band") ole_map.Object.Layers.Add(lycur) bandrec = lycur.records bandline = bandrec.fields.item("shape").value lycur.connecttonewobject("mapobjects2.maplayer") lycur.GeoDataset = dcshp.FindGeoDataset("air_point") ole_map.Object.Layers.Add(lycur) contourrec = lycur.records string theid, therq therq = "990101" double thevalue do until(contourrec.eof) jcpoint[UpperBound(jcpoint) + 1] = contourrec.fields.item("shape").value.x jcpoint[UpperBound(jcpoint) + 1] = contourrec.fields.item("shape").value.y theid = contourrec.fields.item("id").value SELECT jc.tsp INTO :thevalue FROM jc WHERE ( jc.p_code = :theid ) AND ( jc.str_date = :therq ) ; // messagebox("",string(thevalue)) jcpoint[UpperBound(jcpoint) + 1] = thevalue jccount ++ contourrec.movenext() loop bandpoint[1] = bandline.extent.left bandpoint[2] = bandline.extent.bottom bandpoint[3] = bandline.extent.right bandpoint[4] = bandline.extent.top 2.生成等值线: //messagebox("",string(ole_map.object.layers.count())) if(ole_map.object.layers.count() > 2) then ole_map.object.layers.remove(0) end if string outputfname = "contours" string file_name file_name= shppath + "\" + outputfname double thewgjl,thexs contourstep = 0.01 issqrt = -2 thewgjl = 4000 thexs = 0.5 string strref strref = string(bandpoint[1]) + "," + string(bandpoint[2]) + "," + string(bandpoint[3]) + "," + string(bandpoint[4]) + "," strref = strref + string(issqrt) + "," + string(thewgjl) + "," + string(contourstep) + "," + string(thexs) + "," + file_name + "," + string(jccount) int i for i = 1 to upperbound(jcpoint) strref = strref + "," + string(jcpoint) next strref = strref + "," //messagebox("",strref) GetContours(strref) //调用计算等值线的dll oleobject lycur lycur = create oleobject lycur.connecttonewobject("mapobjects2.maplayer") lycur.GeoDataset = dcshp.FindGeoDataset(outputfname) ole_map.Object.Layers.Add(lycur) ole_map.object.refresh() 3.等值线2范围面的函数: contourstep = contourstep * 1000 oleobject lycur lycur = Create oleobject oleObject bandrec,contourrec,beforerec,thisrec oleObject bandline,contourline,theline,contourpolygon,closepolygon[] double contourvalue,closevalue[] integer pointcount contourpolygon = create oleobject contourpolygon.connecttonewobject("mapobjects2.polygon") bandrec = ole_map.object.layers.item("band").records bandline = bandrec.fields.item("shape").value contourrec = ole_map.object.layers.item("contours").records lycur.connecttonewobject("mapobjects2.maplayer") lycur.GeoDataset = dcshp.FindGeoDataset("contours_polygon") //ole_map.Object.Layers.Add(lycur) oleobject pgrec pgrec = lycur.records if(not pgrec.eof) then pgrec.edit() do until(pgrec.eof) pgrec.delete() pgrec.movenext() loop end if //先将开曲线端点围绕边界按逆时针排列 oleobject thepoint[],theline[] double thevalue[] integer thetimes[],thebian[],anotherindex[],j,i = 1 contourrec.movefirst() do until(contourrec.eof) contourline = contourrec.fields.item("shape").value contourvalue = contourrec.fields.item("valu").value pointcount = contourline.parts.item(0).count() if(contourline.parts.item(0).item(0).x = contourline.parts.item(0).item(pointcount - 1).x and & contourline.parts.item(0).item(0).y = contourline.parts.item(0).item(pointcount - 1).y) then //如果封闭 contourpolygon.connecttonewobject("mapobjects2.polygon") contourpolygon.parts.add(contourline.parts.item(0)) pgrec.addnew() pgrec.fields.item("shape").value = contourpolygon pgrec.fields.item("value").value = contourvalue pgrec.fields.item("flag").value = 1 pgrec.update() closepolygon[UpperBound(closepolygon) + 1] = contourpolygon closevalue[UpperBound(closevalue) + 1] = contourvalue contourrec.movenext() continue end if thepoint = contourline.parts.item(0).item(0) theline = contourline thevalue = contourvalue anotherindex = i + 1 thepoint[i + 1] = contourline.parts.item(0).item(pointcount - 1) theline[i + 1] = contourline thevalue[i + 1] = contourvalue anotherindex[i + 1] = i i = i + 2 contourrec.movenext() loop for i = 1 to UpperBound(thepoint) thetimes = 0 if(abs(thepoint.y - bandline.extent.bottom)<1) then thebian = 10 elseif(abs(thepoint.x - bandline.extent.right)<1) then thebian = 20 elseif(abs(thepoint.y - bandline.extent.top)<1) then thebian = 30 elseif(abs(thepoint.x - bandline.extent.left)<1) then thebian = 40 end if next //messagebox("ok","ok1") oleobject pband1,pband2,pband3,pband4 pband1 =create oleobject pband2 =create oleobject pband3 =create oleobject pband4 =create oleobject i = UpperBound(thepoint) i++ pband1.connecttonewobject("mapobjects2.point") pband1.x = bandline.extent.left pband1.y = bandline.extent.bottom thepoint = pband1 theline = bandline thevalue = 0 anotherindex = 0 thebian = 5 thetimes = 1 i++ pband2.connecttonewobject("mapobjects2.point") pband2.x = bandline.extent.right pband2.y = bandline.extent.bottom thepoint = pband2 theline = bandline thevalue = 0 anotherindex = 0 thebian = 15 thetimes = 1 i++ pband3.connecttonewobject("mapobjects2.point") pband3.x = bandline.extent.right pband3.y = bandline.extent.top thepoint = pband3 theline = bandline thevalue = 0 anotherindex = 0 thebian = 25 thetimes = 1 i++ pband4.connecttonewobject("mapobjects2.point") pband4.x = bandline.extent.left pband4.y = bandline.extent.top thepoint = pband4 theline = bandline thevalue = 0 anotherindex = 0 thebian = 35 thetimes = 1 //messagebox("ok","ok2") oleobject templine,temppoint integer tempbian,tempanotherindex,temptimes double tempvalue boolean change = false for i = 1 to UpperBound(thepoint) for j = i + 1 to UpperBound(thepoint) if(thebian[j] > thebian) then change = false elseif(thebian[j] < thebian) then change = true elseif(thebian = 10 and thepoint[j].x < thepoint.x) then change = true elseif(thebian = 20 and thepoint[j].y < thepoint.y) then change = true elseif(thebian = 30 and thepoint[j].x > thepoint.x) then change = true elseif(thebian = 40 and thepoint[j].y > thepoint.y) then change = true else change = false end if if(change) then temppoint = thepoint templine = theline tempbian = thebian tempanotherindex = anotherindex tempvalue = thevalue temptimes = thetimes thepoint = thepoint[j] thepoint[j] = temppoint thebian = thebian[j] thebian[j] = tempbian if(anotherindex <> j) then theline = theline[j] thetimes = thetimes[j] anotherindex = anotherindex[j] thevalue = thevalue[j] if(anotherindex > 0) then anotherindex[anotherindex] = i theline[j] = templine thetimes[j] = temptimes anotherindex[j] = tempanotherindex thevalue[j] = tempvalue if(anotherindex[j] > 0) then anotherindex[anotherindex[j]] = j end if end if next next integer index oleobject mypoints mypoints = create oleobject mypoints.connecttonewobject("mapobjects2.points") //messagebox("ok","ok3") double minvalue,maxvalue integer inum for i = 1 to UpperBound(thepoint) if(thetimes > 1) then continue minvalue=1000000 maxvalue=-1000000 index = i mypoints.connecttonewobject("mapobjects2.points") mypoints.add(thepoint[index]) thetimes[index] = thetimes[index] + 1 do while(true) if(index = UpperBound(thepoint)) then index = 1 else index++ end if if(index = i) then exit mypoints.add(thepoint[index]) thetimes[index] = thetimes[index] + 1 if(anotherindex[index] = 0) then continue pointcount = theline[index].parts.item[0].count() if(theline[index].parts.item[0].item[0].x = thepoint[index].x and & theline[index].parts.item[0].item[0].y = thepoint[index].y) then for inum = 0 to (pointcount - 1) step 1 mypoints.add(theline[index].parts.item[0].item[inum]) next else for inum = (pointcount - 1) to 0 step -1 mypoints.add(theline[index].parts.item[0].item[inum]) next end if if(thevalue[index] < minvalue) then minvalue = thevalue[index] if(thevalue[index] > maxvalue) then maxvalue = thevalue[index] index = anotherindex[index] if(index = i) then exit thetimes[index] = thetimes[index] + 1 loop contourpolygon.connecttonewobject("mapobjects2.polygon") contourpolygon.parts.add(mypoints) pgrec.addnew() pgrec.fields.item("shape").value = contourpolygon pgrec.fields.item("value").value = minvalue if(minvalue = maxvalue) then pgrec.fields.item("flag").value = 1 //表示还需处理的 else pgrec.fields.item("flag").value = 0 end if pgrec.update() closepolygon[UpperBound(closepolygon) + 1] = contourpolygon // closevalue[UpperBound(closevalue) + 1] = contourvalue next pgrec.stopediting() oleobject lyjg lyjg = create oleobject lyjg.connecttonewobject("mapobjects2.maplayer") lyjg.GeoDataset = dcshp.FindGeoDataset("contours_jg") ole_map.Object.Layers.Add(lyjg) oleobject jgrec,befrec,aftrec jgrec = lyjg.records integer theflag if(not jgrec.eof) then jgrec.edit() do until(jgrec.eof) jgrec.delete() jgrec.movenext() loop end if oleobject initpolygon oleobject cutpolygon oleobject jgpolygon //double themin = 1000000 //pgrec.movefirst() //do until(pgrec.eof) // if(themin > pgrec.fields.item("value").value) then // themin = pgrec.fields.item("value").value //pgrec.movenext //loop oleobject mypolygon[] integer myflag[] double mycontour[] pgrec.movefirst() do until(pgrec.eof) initpolygon = pgrec.fields.item("shape").value minvalue = pgrec.fields.item("value").value theflag = pgrec.fields.item("flag").value // if(theflag =0) then // jgrec.addnew() // jgrec.fields.item("shape").value = initpolygon // jgrec.fields.item("minvalue").value = minvalue // jgrec.fields.item("range").value = string(minvalue) + "--" +string(minvalue + contourstep) // jgrec.update() // // pgrec.movenext() // continue // end if mypolygon[UpperBound(mypolygon) + 1] = initpolygon mycontour[UpperBound(mycontour) + 1] = minvalue myflag[UpperBound(myflag) + 1] = theflag pgrec.movenext() loop for i = 1 to UpperBound(mypolygon) minvalue=1000000 maxvalue=-1000000 if(mycontour < minvalue) then minvalue = mycontour if(mycontour > maxvalue) then maxvalue = mycontour jgpolygon = mypolygon for j = 1 to UpperBound(mypolygon) if(i = j) then continue if(isnull(jgpolygon)) then messagebox("出错提示","TOPO运算有问题,可能是seft_insertect造成!") // pg1 = mypolygon // pg2 = mypolygon[j] // aaa = true // ole_map.object.trackinglayer.refresh(true) jgpolygon = mypolygon continue end if if(abs(abs(mycontour[j] - mycontour) - contourstep) > 0.0000001 and abs(mycontour[j] - mycontour) > 0.000001) then continue if(myflag = 0 and mycontour[j] - mycontour < -0.0001) then continue //范围在minv--minv+dgj 排除minv-dgj if(mypolygon.IsPointIn(mypolygon[j].parts.item[0].item[0]) and mypolygon.IsPointIn(mypolygon[j].Centroid)) then jgpolygon = jgpolygon.Difference(mypolygon[j]) if(mycontour[j] < minvalue) then minvalue = mycontour[j] if(mycontour[j] > maxvalue) then maxvalue = mycontour[j] end if // end if next jgrec.addnew() jgrec.fields.item("shape").value = jgpolygon jgrec.fields.item("minvalue").value = minvalue if(minvalue = maxvalue) then jgrec.fields.item("range").value = "done know" else jgrec.fields.item("range").value = string(minvalue) + "--" + string(maxvalue) end if jgrec.update() next jgrec.stopediting() oleobject donerec,xjrec,doneshape double donevalue,xjvalue do while(true) donerec = lyjg.SearchExpression("range = ~'done know~'") if(donerec.eof) then exit do until(donerec.eof) donevalue = donerec.fields.item("minvalue").value doneshape = donerec.fields.item("shape").value xjrec = lyjg.SearchShape(doneshape,5,"") if(xjrec.eof) then donerec.movenext() continue elseif(xjrec.count() < 2) then donerec.movenext() continue end if xjvalue = xjrec.fields.item("minvalue").value if(abs(donevalue - xjvalue) < 0.1) then //可能是自己 xjrec.movenext() xjvalue = xjrec.fields.item("minvalue").value end if // messagebox("",string(xjvalue)) // messagebox("",string(donevalue)) donerec.edit() if(abs(donevalue - xjvalue) < 0.1) then donerec.fields.item("minvalue").value = donevalue - contourstep donerec.fields.item("range").value = string(donevalue - contourstep) + "--" + string(donevalue) else donerec.fields.item("minvalue").value = donevalue donerec.fields.item("range").value = string(donevalue) + "--" + string(donevalue + contourstep) end if donerec.update() donerec.movenext() loop donerec.stopediting() loop //oleobject strsUniqueValues //strsUniqueValues = create oleobject //strsUniqueValues.connecttonewobject("mapobjects2.Strings") jgrec = lyjg.records jgrec.MoveFirst() Do until(jgrec.EOF) // strsUniqueValues.Add( jgrec.fields.item("minvalue").Value) strsUniqueValues[upperbound(strsUniqueValues) + 1] = jgrec.fields.item("minvalue").Value jgrec.MoveNext() Loop double doutemp For i = 1 To upperbound(strsUniqueValues) for j = i + 1 to upperbound(strsUniqueValues) if(strsUniqueValues > strsUniqueValues[j]) then doutemp = strsUniqueValues strsUniqueValues = strsUniqueValues[j] strsUniqueValues[j] = doutemp end if next next oleobject vren vren = create oleobject vren.connecttonewobject("mapobjects2.valuemaprenderer") lyjg.Renderer = vren lyjg.Renderer.SymbolType = 2 lyjg.Renderer.Field = "minvalue" lyjg.Renderer.ValueCount = upperbound(strsUniqueValues) integer green,greenstep greenstep = 100 / upperbound(strsUniqueValues) For i = 0 To upperbound(strsUniqueValues) - 1 green = 50 + (greenstep * i) lyjg.Renderer.Value = strsUniqueValues[i+1] lyjg.Renderer.Symbol(i).Color = rgb(0,green,0) lyjg.renderer.symbol(i).outline = false Next ole_map.object.refresh() destroy lycur |
|
7楼#
发布于:2003-09-13 14:56
有没有VB的代码呀,我看不懂!!
|
|
8楼#
发布于:2003-09-14 16:11
对啊。我也想要VB代码。这个代码看不懂
|
|