本文介绍了当我在项目中使用DLL时,不会采用文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个dll名称是PointinPolygon1,这里有两个类文件,名称是pointk和polygon



这里我粘贴我的代码



PointinPolygon1.cs

i have created one dll name is PointinPolygon1 in this have two class files the name is pointk and polygon

here i paste my code

PointinPolygon1.cs

public  class PointinPolygon1
    {
        public Polygon poly = new Polygon();
        public Pointk pt;
        public int count = 0;
        //string latti;
        double pi = 3.14159;
        double earthRadius = 3964.037911746;
       // pt=new Point(15.219171, 78.691695);
         public bool PointInPolygon(Pointk point, Polygon polygon)
         {
             int i,j,nvert=polygon.Points.Count();
             bool c=false;
             for(i=0,j=nvert-1;i<nvert;j=i++)
             {
                 Pointk iPt=polygon.getPointAtIndex(i);
                 Pointk jPt=polygon.getPointAtIndex(j);
                 if(((iPt.longitude>=point.longitude)!=(jPt.longitude>=point.longitude))&&(point.lattitude<=(jPt.lattitude-iPt.lattitude)*(point.longitude-iPt.longitude)/(jPt.longitude-iPt.longitude)+iPt.lattitude))
                     c=!c;


             }
             return c;
         }
        public Pointk Addmovementsperhour(double heading,double speedMph,TimeSpan Duration,Pointk point1)
         {
             double x = speedMph * System.Math.Sin(heading * pi / 180) * Duration.TotalSeconds / 3600;
             double y = speedMph * System.Math.Cos(heading * pi / 180) * Duration.TotalSeconds / 3600;
             double newLat = point1.lattitude + 180 / pi * y / earthRadius;
             double newlong = point1.longitude + 180 / pi / System.Math.Sin(point1.lattitude * pi / 180) * x / earthRadius;
             return new Pointk(newLat, newlong);
         }
        public Boolean getpolygonvalues(double heading, double speed, double lattitude, double longitude)
        {

            List<Polygon> polygonList = new List<Polygon>();
            string path = @"f:\Polygon.txt";

            string[] Polygonpoints = File.ReadAllLines(path);
            for (int i = 0; i < Polygonpoints.Length; i++)
            {
                string s1 = Polygonpoints[i];
                string[] A = s1.Split('=');
                if (A[0].Trim() == "PolygonPoints")
                {
                    poly = new Polygon();
                    string S2 = A[1].Trim();
                    string [] B=S2.Split(' ');
                    foreach(string Polygon in B)
                    {
                        string[] S3 = Polygon.Split(',');
                        Pointk pt1 = new Pointk(Convert.ToDouble(S3[1]),Convert.ToDouble(S3[0]));
                        poly.addPoint(pt1);
                    }
                }
                else if (A[0].Trim() == "PolygonName")
                {
                    poly.setPolygonName(A[1].Trim().ToString());
                }
                else if (A[0].Trim() == "AirPortCode")
                {
                    poly.setAirportName(A[1].Trim().ToString());
                    polygonList.Add(poly);
                }
            }
            pt=new Pointk(15.219171, 78.691695);
            Pointk lpoint = Addmovementsperhour(50, 50, TimeSpan.FromSeconds(10), pt);
            Pointk mpoint = Addmovementsperhour(55, 50, TimeSpan.FromSeconds(10), pt);
            Pointk rpoint = Addmovementsperhour(60, 50, TimeSpan.FromSeconds(10), pt);
            for (int i = 0; i < polygonList.Count; i++)
            {
                Polygon tpoly = (Polygon)polygonList[i];
                Boolean retval = false;
                retval = PointInPolygon(pt, tpoly);
                if (retval)
                    return retval;
                retval = PointInPolygon(lpoint, tpoly);
                if (retval)
                    return retval;
                retval = PointInPolygon(mpoint, tpoly);
                if (retval)
                    return retval;
                retval = PointInPolygon(rpoint, tpoly);
                if (retval)
                    return retval;
            }

            return false;
        }
    }



pointk.cs




pointk.cs

public class Pointk
    {
        public double lattitude;
        public double longitude;
        public Pointk(double x, double y)
        {
            lattitude = x;
            longitude = y;
        }




    }



Polygon.cs


Polygon.cs

public class Polygon
    {
        public List<Pointk> Points;
        string Polygonname;
        string AirportName;

        public Polygon()
        {
            Points = new List<Pointk>();
        }
        public void addPoint(Pointk p)
        {
            Points.Add(p);
        }

        public string getPolygonName()
        {
            return Polygonname;
        }
        public string getairportname()
        {
            return AirportName;
        }
        public void setAirportName(string Aname)
        {
            AirportName = Aname;
        }

        public void setPolygonName(string name)
        {
            Polygonname = name;
        }

        public Pointk getPointAtIndex(int index)
        {
            return (Pointk)Points[index];
        }

    }







之后工作正常创建为dll然后使用另一个窗口应用程序按钮单击事件






it is work fine after creating as a dll and then using another window application button click event

PointinPolygon1 obj = new PointinPolygon1();
            bool x = obj.getpolygonvalues(50, 50, -97.08215655572718, 32.90984427311083);
            label1.Text = x.ToString();





i当我到达断点时以断点运行/>



i am run with break point when i reach the break point

bool x = obj.getpolygonvalues(50, 50, -97.08215655572718, 32.90984427311083);



i我收到错误


i am getting error

Input string was not in a correct format.



请告诉我原因



我尝试过的事情:



i我不能传递参数


please tell me the reason

What I have tried:

i am not able to pass the argument

推荐答案


这篇关于当我在项目中使用DLL时,不会采用文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 19:53
查看更多