Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Polygon Util
//Rextester.Program.Main is the entry point for your code. Don't change it. //Microsoft (R) Visual C# Compiler version 2.9.0.63208 (958f2354) using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using Newtonsoft.Json; namespace Rextester { public class Program { public static void Main(string[] args) { var d = CreatePolygon(0,0,0.3048,0.3048,1,2); Console.WriteLine (JsonConvert.SerializeObject(d)); } public static Model.Polygonjson CreatePolygon(double X1, double Y1, double xvalue, double yvalue, int Xaxis, int yAxis) { var JsonOutput = new Model.Polygonjson(); for (int M = 1; M <= yAxis; M++) { for (int j = 1; j <= Xaxis; j++) { var georecord = new Model.GeomCenterCell(); georecord.type = "Polygon"; if (georecord.coordinates == null) { georecord.coordinates = new List<List<List<double>>>(); } var record = new Model.Dataum(); record.Case = "on-grade"; record.timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); var Coordinates = new List<List<double>>(); var Point1 = new List<double>(); var Point2 = new List<double>(); var Point3 = new List<double>(); var Point4 = new List<double>(); var Point5 = new List<double>(); for (int k = 0; k < 5; k++) { if (k == 0) { Point1.Add(X1 + ((j - 1) * xvalue)); Point1.Add(Y1 + ((M - 1) * yvalue)); } else if (k == 1) { Point2.Add(X1 + ((j - 1) * xvalue)); Point2.Add(Y1 + (M * yvalue)); } else if (k == 2) { Point3.Add(X1 + (j * xvalue)); Point3.Add(Y1 + (M * yvalue)); } else if (k == 3) { Point4.Add(X1 + (j * xvalue)); Point4.Add(Y1 + ((M - 1) * yvalue)); } else if (k == 4) { Point5.Add(X1 + ((j - 1) * xvalue)); Point5.Add(Y1 + ((M - 1) * yvalue)); } } Coordinates.Add(Point1); Coordinates.Add(Point2); Coordinates.Add(Point3); Coordinates.Add(Point4); Coordinates.Add(Point1); georecord.coordinates.Clear(); georecord.coordinates.Add(Coordinates); record.geom_center_cell = georecord; if (JsonOutput.data == null) { JsonOutput.data = new List<Model.Dataum>(); } JsonOutput.data.Add(record); } JsonOutput.proj4text = "+proj=tmerc +lat_0=36.666666666667 +lon_0=-90.166666666667 +k_0=0.9999411764706 +a=6378137.0000001015 +b=6356752.314140457 +x_0=699999.9999999898 +y_0=0.0 +towgs84=0.0,0.0,0.0 +units=m +no_defs"; JsonOutput.machine_id = "G301"; } return JsonOutput; } } public class Model { public class GeomCenterCell { public string type; public List<List<List<double>>> coordinates; } public class Dataum { public object timestamp; public GeomCenterCell geom_center_cell; public string Case; } public class Polygonjson { public string proj4text; public string machine_id; public List<Dataum> data; } } }
run
|
edit
|
history
|
help
0
hello world
koko
sulu
Update 2D Array
Project Euler No 2
azsdfghju654 ffddfdf
PYRAMIDPATTERN
งานสอบ
RegularExpressions
test using C#2019