public void loadShape(string fileName, string parentName, string prefix, Material mat, int elevation)
    {
        GameObject parent    = GameObject.Find(parentName);
        ShapeFile  shapeFile = new ShapeFile();

        shapeFile.ReadShapes(fileName, 2000000, 1, 2000000, 1);
        //shapeFile.ReadShapes(fileName, 0, 18120, 0, 12620.000100000063);
        //shapeFile.Read(fileName);


        int i = 0;

        for (int k = 0; k < shapeFile.MyRecords.Count; k++)
        {
            ShapeFileRecord rec = shapeFile.MyRecords[k];
            GameObject      newGameObject;

            Vector2[] listPoint = new Vector2[rec.Points.Count - 1];

            string vert = "";

            for (int j = 0; j < rec.Points.Count - 1; j++)
            {
                Vector2 v  = rec.Points[j];
                Vector2 v2 = v;//new Vector2(v.x - 371000, v.y - 6549000);
                v2           = new Vector2(v.x - 371000, v.y - 6549000);
                listPoint[j] = v2;
                vert        += v2;
            }

            newGameObject = new GameObject(prefix + "_" + i);

            newGameObject.AddComponent(typeof(MeshRenderer));
            newGameObject.AddComponent(typeof(MeshFilter));

            newGameObject.GetComponent <MeshFilter>().mesh      = new MeshCreator().CreateMesh(elevation, listPoint);
            newGameObject.GetComponent <MeshFilter>().mesh.name = "CustomMesh";
            newGameObject.GetComponent <Renderer>().material    = mat;
            newGameObject.transform.localScale = new Vector3(0.2f, 0.2f, 0.2f);

            newGameObject.GetComponent <Transform>().SetParent(parent.GetComponent <Transform>());
            newGameObject.AddComponent <Land_Use>();
            newGameObject.AddComponent <MeshCollider>();

            newGameObject.GetComponent <Land_Use>().lu_name       = prefix + "_" + i;
            newGameObject.GetComponent <Land_Use>().lu_code       = i;
            newGameObject.GetComponent <Land_Use>().population    = i;
            newGameObject.GetComponent <Land_Use>().expro_cost    = i;
            newGameObject.GetComponent <Land_Use>().density_class = prefix + "_CLASSE_DENSITE_" + i;

            i++;
        }
    }
    // Use this for initialization
    void Start()
    {
        Debug.Log("Lest's start the import operation");

        // Create Vector2 vertices
        vertices2D = new Vector2[] { new Vector2(0, 0), new Vector2(10, 5), new Vector2(10, 10) };

        triangulator = new Triangulator(vertices2D);

        string    fileName  = "/Users/sklab/Desktop/TODELETE/zone_etude/zones241115.shp";
        ShapeFile shapeFile = new ShapeFile();

        shapeFile.ReadShapes(fileName, 2000000, 1, 2000000, 1);



        int i = 0;

        foreach (ShapeFileRecord rec in shapeFile.MyRecords)
        {
            GameObject poly;
            Debug.Log("---> The record number is : " + rec.RecordNumber);
            Debug.Log("---> The record Content length is : " + rec.ContentLength);
            Debug.Log("---> The record Shape type is : " + rec.ShapeType);
            Debug.Log("---> The record number of parts is : " + rec.NumberOfParts);
            Debug.Log("---> The record number of points is : " + rec.NumberOfPoints);
            Debug.Log("---> the record attributes are: " + rec.Attributes);


            Vector2[] listPoint = new Vector2[rec.Points.Count];
            int       j         = 0;
            foreach (Vector2 v in rec.Points)
            {
                listPoint[j] = v;
                j++;
            }
            triangulator.SetPoints(listPoint);

            poly = new GameObject("Poly_" + i);

            poly.AddComponent(typeof(MeshRenderer));
            poly.AddComponent(typeof(MeshFilter));
            CreateMesh(40, poly.GetComponent <MeshFilter>().mesh);
            poly.GetComponent <MeshFilter>().mesh.name = "CustomMesh";
            poly.GetComponent <Renderer>().material    = myNewMaterial;
            //poly.transform.localScale = new Vector3(45f, 45f, 45f);

            i++;
        }
    }
Beispiel #3
0
        // Start is called before the first frame update
        void Start()
        {
            Debug.Log("Let's try to read a shapefile!");
            fileName = "/Users/sklab/Desktop/TODELETE/zone_etude/zones241115.shp";

            shapeFile = new ShapeFile();

            //shapeFile.ReadShapes(fileName, 200000, 1, 200000, 1);
            shapeFile.ReadShapes(fileName, 18120, 0, 12620.000100000063, 0);

            //shapeFile.Read(fileName);

            Debug.Log("Good, file was read.");

            Debug.Log(shapeFile.ToString());

            Debug.Log(shapeFile.FileHeader.ToString());



            foreach (ShapeFileRecord rec in shapeFile.MyRecords)
            {
                Debug.Log("---> The record number is : " + rec.RecordNumber);
                Debug.Log("---> The record Content length is : " + rec.ContentLength);
                Debug.Log("---> The record Shape type is : " + rec.ShapeType);
                Debug.Log("---> The record number of parts is : " + rec.NumberOfParts);
                Debug.Log("---> The record number of points is : " + rec.NumberOfPoints);

                Debug.Log("---> the record attributes are: " + rec.Attributes);

                foreach (Vector2 v in rec.Points)
                {
                    //Debug.Log("---> the point is: " + v);
                }
            }
        }