void Start() { ShapeFile shapeFile = new ShapeFile(); shapeFile.Read(path); Debug.Log(shapeFile.ToString()); List <Vector3> vertices = new List <Vector3>(); foreach (ShapeFileRecord record in shapeFile.Records) { foreach (Vector3 point in record.Points) { vertices.Add(point); Debug.Log(point); } foreach (Vector3 point in vertices) { Debug.Log(point); } } }
// 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); } } }
void Start() { //UnityEngine.Random.InitState(0); elevations = new List <float>(); //float[] seed = new float[octaves]; //for (int i = 0; i < octaves; i++) //{ // seed[i] = Random.Range(0.0f, 100.0f); //} Polygon polygon = new Polygon(); ShapeFile shapeFile = new ShapeFile(); shapeFile.Read(path); List <double> MinMax = shapeFile.FileHeader.GetMinMax(); double xMin = MinMax[0]; double xMax = MinMax[1]; double yMin = MinMax[2]; double yMax = MinMax[3]; int intxMin = (int)Math.Floor(xMin); int intxMax = (int)Math.Ceiling(xMax); int intyMin = (int)Math.Floor(yMin); int intyMax = (int)Math.Ceiling(yMax); Debug.Log(xMin); Debug.Log(intxMin); Debug.Log(yMin); Debug.Log(intyMin); xsize = 0; ysize = 0; Debug.Log(shapeFile.ToString()); //PoissonDiscSampler sampler = new PoissonDiscSampler(xsize, ysize, minPointRadius); //// Add uniformly-spaced points //foreach (Vector2 sample in sampler.Samples()) { // polygon.Add(new Vertex((double)sample.x, (double)sample.y)); //} //Add some randomly sampled points //for (int i = 0; i < randomPoints; i++) //{ // polygon.Add(new Vertex(Random.Range(0.0f, xsize), Random.Range(0.0f, ysize))); // xpoint = Random.Range(0.0f, xsize); // ypoint = Random.Range(0.0f, ysize); // Debug.Log(xpoint); // Debug.Log(ypoint); //} foreach (ShapeFileRecord record in shapeFile.Records) { foreach (Vector3 point in record.Points) { polygon.Add(new Vertex((double)point.x, (double)point.y)); xpoint = point.x; ypoint = point.y; xsize += 1; ysize += 1; elevations.Add(point.z); } } TriangleNet.Meshing.ConstraintOptions options = new TriangleNet.Meshing.ConstraintOptions() { ConformingDelaunay = true }; mesh = (TriangleNet.Mesh)polygon.Triangulate(options); // //bin = new TriangleBin(mesh, xsize, ysize, minPointRadius); // Sample perlin noise to get elevations //foreach (Vertex vert in mesh.Vertices) //{ // float elevation = 0.0f; // float amplitude = Mathf.Pow(persistence, octaves); // float frequency = 1.0f; // float maxVal = 0.0f; // for (int o = 0; o < octaves; o++) // { // float sample = (Mathf.PerlinNoise(seed[o] + (float)vert.x * sampleSize / (float)xsize * frequency, // seed[o] + (float)vert.y * sampleSize / (float)ysize * frequency) - 0.5f) * amplitude; // elevation += sample; // maxVal += amplitude; // amplitude /= persistence; // frequency *= frequencyBase; // } // elevation = elevation / maxVal; // Debug.Log(elevation); // Debug.Log(elevation * elevationScale); // elevations.Add(elevation * elevationScale); //} //foreach (ShapeFileRecord record in shapeFile.Records) //{ // foreach (Vector3 point in record.Points) // { // foreach (Vertex vert in mesh.Vertices) // { // elevations.Add(point.z); // zpoint = point.z; // Debug.Log(zpoint); // } // } // } MakeMesh(); //ScatterDetailMeshes(); }