예제 #1
0
        //"1,1;2,2;3,3"
        public static void Main(string[] args)
        {
            //args = new string[3];
            //string ss = "0,0;0,1;1,1;1,0";
            //string ss1 = "0,0;0,1;1,1;1,0";
            //string ss2 = "0";
            //args[0] = ss;
            //args[1] = ss1;
            //args[2] = ss2;

            if (args?.Count() != 3)
            {
                return;
            }
            try
            {
                string[] ptStr1 = args[0].Split(';');
                string[] ptStr2 = args[1].Split(';');
                //0:相差  1:相交  2:异或  3:合并
                GpcOperation operation = (GpcOperation)(int.Parse(args[2]));
                //组织多边形A顶点数据
                GpcWrapper.Polygon polygonA = new GpcWrapper.Polygon();
                PointF[]           aa       = new PointF[ptStr1.Count()];
                for (int i = 0; i < ptStr1.Count(); i++)
                {
                    var subPtStr = ptStr1[i].Split(',');
                    aa[i] = new PointF(float.Parse(subPtStr[0]),
                                       float.Parse(subPtStr[1]));
                }
                VertexList vtxA = new VertexList(aa);
                polygonA.AddContour(vtxA, false);

                //组织多边形B顶点数据
                GpcWrapper.Polygon polygonB = new GpcWrapper.Polygon();
                PointF[]           bb       = new PointF[ptStr2.Count()];
                for (int i = 0; i < ptStr2.Count(); i++)
                {
                    var subPtStr = ptStr2[i].Split(',');
                    bb[i] = new PointF(float.Parse(subPtStr[0]),
                                       float.Parse(subPtStr[1]));
                }
                VertexList vtxB = new VertexList(bb);
                polygonB.AddContour(vtxB, false);
                //调用GPC库的剪辑算法
                GpcWrapper.Polygon result = polygonA.Clip(operation, polygonB);
                //组织返回结果字符串
                if (result.Contour == null || result.Contour.Count() == 0)
                {
                    Console.WriteLine("");
                    return;
                }
                string str = string.Join(";", result.Contour[0].Vertex);
                str = str.Replace("(", string.Empty).Replace(")", string.Empty);
                Console.WriteLine(str);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
예제 #2
0
        public static Polygon Clip(GpcOperation operation, Polygon subject_polygon, Polygon clip_polygon)
        {
            gpc_polygon gpc_polygon         = new gpc_polygon();
            gpc_polygon gpc_subject_polygon = GpcWrapper.PolygonTo_gpc_polygon(subject_polygon);
            gpc_polygon gpc_clip_polygon    = GpcWrapper.PolygonTo_gpc_polygon(clip_polygon);

            gpc_polygon_clip(operation, ref gpc_subject_polygon, ref gpc_clip_polygon, ref gpc_polygon);
            Polygon polygon = GpcWrapper.gpc_polygon_ToPolygon(gpc_polygon);

            GpcWrapper.Free_gpc_polygon(gpc_subject_polygon);
            GpcWrapper.Free_gpc_polygon(gpc_clip_polygon);
            GpcWrapper.gpc_free_polygon(ref gpc_polygon);

            return(polygon);
        }
예제 #3
0
        public static Tristrip ClipToTristrip(GpcOperation operation, Polygon subject_polygon, Polygon clip_polygon)
        {
            gpc_tristrip gpc_strip           = new gpc_tristrip();
            gpc_polygon  gpc_subject_polygon = GpcWrapper.PolygonTo_gpc_polygon(subject_polygon);
            gpc_polygon  gpc_clip_polygon    = GpcWrapper.PolygonTo_gpc_polygon(clip_polygon);

            gpc_tristrip_clip(operation, ref gpc_subject_polygon, ref gpc_clip_polygon, ref gpc_strip);
            Tristrip tristrip = GpcWrapper.gpc_strip_ToTristrip(gpc_strip);

            GpcWrapper.Free_gpc_polygon(gpc_subject_polygon);
            GpcWrapper.Free_gpc_polygon(gpc_clip_polygon);
            GpcWrapper.gpc_free_tristrip(ref gpc_strip);

            return(tristrip);
        }
        public static Tristrip ClipToTristrip( GpcOperation operation, Polygon subject_polygon, Polygon clip_polygon )
        {
            gpc_tristrip gpc_strip = new gpc_tristrip();
            gpc_polygon gpc_subject_polygon = GpcWrapper.PolygonTo_gpc_polygon( subject_polygon );
            gpc_polygon gpc_clip_polygon    = GpcWrapper.PolygonTo_gpc_polygon( clip_polygon );

            gpc_tristrip_clip( operation, ref gpc_subject_polygon, ref gpc_clip_polygon, ref gpc_strip );
            Tristrip tristrip = GpcWrapper.gpc_strip_ToTristrip( gpc_strip );

            GpcWrapper.Free_gpc_polygon( gpc_subject_polygon );
            GpcWrapper.Free_gpc_polygon( gpc_clip_polygon );
            GpcWrapper.gpc_free_tristrip( ref gpc_strip );

            return tristrip;
        }
        public static Polygon Clip( GpcOperation operation, Polygon subject_polygon, Polygon clip_polygon )
        {
            gpc_polygon gpc_polygon         = new gpc_polygon();
            gpc_polygon gpc_subject_polygon = GpcWrapper.PolygonTo_gpc_polygon( subject_polygon );
            gpc_polygon gpc_clip_polygon    = GpcWrapper.PolygonTo_gpc_polygon( clip_polygon );

            gpc_polygon_clip( operation, ref gpc_subject_polygon, ref gpc_clip_polygon, ref gpc_polygon );
            Polygon polygon = GpcWrapper.gpc_polygon_ToPolygon( gpc_polygon );

            GpcWrapper.Free_gpc_polygon( gpc_subject_polygon );
            GpcWrapper.Free_gpc_polygon( gpc_clip_polygon );
            GpcWrapper.gpc_free_polygon( ref gpc_polygon );

            return polygon;
        }
예제 #6
0
 private static extern void gpc_tristrip_clip([In]     GpcOperation set_operation,
                                              [In]     ref gpc_polygon subject_polygon,
                                              [In]     ref gpc_polygon clip_polygon,
                                              [In, Out] ref gpc_tristrip result_tristrip);
예제 #7
0
 public Polygon Clip(GpcOperation operation, Polygon polygon)
 {
     return(GpcWrapper.Clip(operation, this, polygon));
 }
예제 #8
0
 public Tristrip ClipToTristrip(GpcOperation operation, Polygon polygon)
 {
     return(GpcWrapper.ClipToTristrip(operation, this, polygon));
 }
예제 #9
0
        private void DoOperation(GpcOperation op)
        {
            GeoPolygonRegion origin = this.m_PolyRegionDict[(int) this.ltvPolygon.CheckedItems[0].Tag];
            try
            {
                switch (op)
                {
                    case GpcOperation.Difference:
                        origin = this.m_PolyRegionExe.GetExcludeRegion(origin, this.m_PolyRegionDict[(int) this.ltvPolygon2.CheckedItems[0].Tag]);
                        goto Label_00A6;

                    case GpcOperation.Intersection:
                        origin = this.DoInsertOper(origin);
                        goto Label_00A6;

                    case GpcOperation.Union:
                        origin = this.DoCombineRegionOper(origin);
                        goto Label_00A6;
                }
            }
            catch (Exception exception)
            {
                MessageBoxUtil.ShowError(exception.Message);
                return;
            }
        Label_00A6:
            if ((origin == null) || (origin.Count == 0))
            {
                MessageBoxUtil.ShowError(GISGlobalResourceEx.GIS_UI_UNINTERSECT_TIP);
            }
            else
            {
                this.m_PolyRegionDict.Add(origin.ID, origin);
                this.TransformPolygonDict(origin.ID, origin);
                this.m_PolygonIDList.Add(origin.ID);
                ListViewItem item = new ListViewItem();
                int num = this.m_PolygonIDList[this.m_PolygonIDList.Count - 1];
                item.Tag = num;
                item.Text = origin.Name;
                this.ltvResult.Items.Add(item);
            }
        }
예제 #10
0
 public GpcTristrip ClipToTristrip(GpcOperation operation, GpcPolygon polygon)
 {
     return GpcWrapper.ClipToTristrip(operation, this, polygon);
 }
예제 #11
0
 public static extern void gpc_polygon_clip([In]     GpcOperation set_operation,
                                            [In]     ref gpc_polygon subject_polygon,
                                            [In]     ref gpc_polygon clip_polygon,
                                            [In, Out] ref gpc_polygon result_polygon);
 public Polygon Clip( GpcOperation operation, Polygon polygon )
 {
     return GpcWrapper.Clip( operation, this, polygon );
 }