Example #1
0
        static public void DisplayLLOnMouseClick()
        {
            ExceptionPanel panel = UIView.library.ShowModal <ExceptionPanel>("ExceptionPanel");

            if (!File.Exists("Files/import_export.conf"))
            {
                panel.SetMessage("GeoSkylines", "no conf file provided!", false);
                return;
            }
            string msg = "";

            Vector3 screenMousePos = Input.mousePosition;
            Ray     mouseRay       = Camera.main.ScreenPointToRay(screenMousePos);
            var     mousePos       = GeoSkylinesTool.RaycastMouseLocation(mouseRay);

            StreamReader confSr = File.OpenText("Files/import_export.conf");
            Dictionary <string, string> conf = new Dictionary <string, string>();

            while (!confSr.EndOfStream)
            {
                string[] keyVal = confSr.ReadLine().Split(':');
                if (keyVal.Length == 2)
                {
                    conf.Add(keyVal[0], keyVal[1]);
                }
            }

            double centerLat = double.Parse(conf["CenterLatitude"]);
            double centerLon = double.Parse(conf["CenterLongitude"]);

            WGS84_UTM convertor  = new WGS84_UTM(null);
            UTMResult centerUTM  = convertor.convertLatLngToUtm(centerLat, centerLon);
            string    ZoneLetter = "S";

            if (centerLat > 0)
            {
                ZoneLetter = "N";
            }

            var    rwoX  = mousePos.x + centerUTM.Easting;
            var    rwoY  = mousePos.y + centerUTM.Northing;
            LatLng rwoLL = convertor.convertUtmToLatLng(rwoX, rwoY, centerUTM.ZoneNumber, ZoneLetter);

            msg += "Screen coordinates (x, y): ";
            msg += screenMousePos.ToString();
            msg += "\n";
            msg += "Game coordinates (x, z): ";
            msg += mousePos.ToString();
            msg += "\n";
            msg += "World coordinates (lon, lat): ";
            msg += rwoLL.Lng.ToString() + "," + rwoLL.Lat.ToString();
            panel.SetMessage("Coordinates", msg, false);
        }
Example #2
0
        // attempt to export whole roads (multisegment) but it doesn't work properly - not used
        public void ExportRoads()
        {
            Debug.Log("EXPORT ROADS");

            ExceptionPanel panel = UIView.library.ShowModal <ExceptionPanel>("ExceptionPanel");
            string         msg   = "";

            if (!File.Exists("Files/import_export.conf"))
            {
                panel.SetMessage("Jan's mod", "no conf file provided!", false);
                return;
            }

            StreamReader confSr = File.OpenText("Files/import_export.conf");
            Dictionary <string, string> conf = new Dictionary <string, string>();

            while (!confSr.EndOfStream)
            {
                string[] keyVal = confSr.ReadLine().Split(':');
                if (keyVal.Length == 2)
                {
                    conf.Add(keyVal[0], keyVal[1]);
                }
            }

            double centerLat = double.Parse(conf["CenterLatitude"]);
            double centerLon = double.Parse(conf["CenterLongitude"]);

            WGS84_UTM convertor  = new WGS84_UTM(null);
            UTMResult centerUTM  = convertor.convertLatLngToUtm(centerLat, centerLon);
            string    ZoneLetter = "S";

            if (centerLat > 0)
            {
                ZoneLetter = "N";
            }

            string columns = "Id,Name,Geometry";

            var a_type     = typeof(NetSegment);
            var properties = a_type.GetProperties();

            foreach (var prop in properties)
            {
                columns = columns + string.Format(",{0}", prop.Name);
            }

            List <string> txtLines = new List <string>
            {
                columns
            };

            NetManager net_manager = NetManager.instance;

            NetSegment[] segments = net_manager.m_segments.m_buffer;
            Dictionary <string, List <NetSegment> > roadsCs = new Dictionary <string, List <NetSegment> >();

            for (int i = 0; i < segments.Length; i++)
            {
                var a_seg = segments[i];
                if (a_seg.Info.ToString().Contains("Highway"))
                {
                    continue;
                }
                var road_name = net_manager.GetSegmentName((ushort)i);
                if (road_name == null || road_name == "")
                {
                    continue; //road_name = "no name " + i.ToString();
                }
                if (!roadsCs.ContainsKey(road_name))
                {
                    roadsCs.Add(road_name, new List <NetSegment>());
                }
                roadsCs[road_name].Add(a_seg);
            }

            int cnt = 0;

            foreach (KeyValuePair <string, List <NetSegment> > road in roadsCs)
            {
                cnt++;
                var road_name = road.Key;
                //string debug_msg = "";
                //debug_msg += "road_name: " + road_name + " | ";
                bool   set_field_info = false;
                string field_info     = "";
                //Dictionary<ushort, ushort> start_end_nodes = new Dictionary<ushort, ushort>();
                Dictionary <string, HashSet <string> > segments_order = new Dictionary <string, HashSet <string> >();
                List <string> road_ends = new List <string>();
                foreach (var a_seg in road.Value)
                {
                    if (!set_field_info)
                    {
                        foreach (var prop in properties)
                        {
                            var prop_val = prop.GetValue(a_seg, null);
                            if (prop_val.ToString().Contains(","))
                            {
                                prop_val = "\"" + prop_val.ToString() + "\"";
                            }
                            field_info += string.Format(",{0}", prop_val);
                        }
                        set_field_info = true;
                    }

                    //debug_msg += "a_seg.m_buildIndex: " + a_seg.m_buildIndex.ToString() + " | ";
                    //debug_msg += "a_seg.m_startNode: " + a_seg.m_startNode.ToString() + ", a_seg.m_endNode: " + a_seg.m_endNode.ToString() + "; ";
                    //debug_msg += "\n";

                    var    startPos   = net_manager.m_nodes.m_buffer[a_seg.m_startNode].m_position;
                    var    startRwoX  = startPos.x + centerUTM.Easting;
                    var    startRwoY  = startPos.z + centerUTM.Northing;
                    LatLng startRwoLL = convertor.convertUtmToLatLng(startRwoX, startRwoY, centerUTM.ZoneNumber, ZoneLetter);

                    var    endPos   = net_manager.m_nodes.m_buffer[a_seg.m_endNode].m_position;
                    var    endRwoX  = endPos.x + centerUTM.Easting;
                    var    endRwoY  = endPos.z + centerUTM.Northing;
                    LatLng endRwoLL = convertor.convertUtmToLatLng(startRwoX, startRwoY, centerUTM.ZoneNumber, ZoneLetter);

                    string startLLid = string.Format("{0} {1}", startRwoLL.Lat, startRwoLL.Lng);
                    string endLLid   = string.Format("{0} {1}", endRwoLL.Lat, endRwoLL.Lng);

                    if (!segments_order.ContainsKey(startLLid))
                    {
                        segments_order[startLLid] = new HashSet <string>();
                        segments_order[startLLid].Add(startLLid);
                        segments_order[startLLid].Add(endLLid);
                        road_ends.Add(startLLid);
                    }
                    else
                    {
                        segments_order[startLLid].Add(startLLid);
                        segments_order[startLLid].Add(endLLid);
                        road_ends.Remove(startLLid);
                    }

                    if (!segments_order.ContainsKey(endLLid))
                    {
                        segments_order[endLLid] = new HashSet <string>();
                        segments_order[endLLid].Add(startLLid);
                        segments_order[endLLid].Add(endLLid);
                        road_ends.Add(endLLid);
                    }
                    else
                    {
                        segments_order[endLLid].Add(startLLid);
                        segments_order[endLLid].Add(endLLid);
                        road_ends.Remove(endLLid);
                    }

                    //if (start_end_nodes.Keys.Contains(a_seg.m_startNode) || start_end_nodes.Values.Contains(a_seg.m_endNode))
                    //    start_end_nodes[a_seg.m_endNode] = a_seg.m_startNode;
                    //else
                    //    start_end_nodes[a_seg.m_startNode] = a_seg.m_endNode;
                }

                string tmp_msg = "road ends(" + road_ends.Count.ToString() + "): ";
                foreach (var road_end in road_ends)
                {
                    tmp_msg += road_end + " | ";
                }
                tmp_msg += "segments_order (" + segments_order.Count.ToString() + "): ";
                foreach (KeyValuePair <string, HashSet <string> > seg_o in segments_order)
                {
                    tmp_msg += seg_o.Key + ": ";
                    foreach (var llid in seg_o.Value)
                    {
                        tmp_msg += llid + " | ";
                    }
                    tmp_msg += "\n";
                }


                panel.SetMessage("GeoSkylines", tmp_msg, false);
                return;



                //IEnumerable<ushort> keys_not_values = start_end_nodes.Keys.AsQueryable().Except(start_end_nodes.Values);
                //debug_msg += "Keys not in values: ";
                //foreach (var key in keys_not_values)
                //    Debug.Log(key);
                //foreach (var key in start_end_nodes.Keys)
                //{
                //    if (!start_end_nodes.Values.Contains(key))
                //        debug_msg += key.ToString();
                //}
                //debug_msg += "\n";
                //debug_msg += "Values not in Keys: ";
                //IEnumerable<ushort> values_not_keys = start_end_nodes.Values.AsQueryable().Except(start_end_nodes.Keys);
                //foreach (var val in values_not_keys)
                //    Debug.Log(val);
                //foreach (var val in start_end_nodes.Values)
                //{
                //    if (!start_end_nodes.Keys.Contains(val))
                //        debug_msg += val.ToString();
                //}
                //debug_msg += "\n";
                //ushort nodeId = res.First();



                //    ushort nodeId = start_end_nodes.Keys.First();
                //    foreach (var key in start_end_nodes.Keys)
                //    {
                //        if (!start_end_nodes.Values.Contains(key))
                //        {
                //            nodeId = key;
                //            break;
                //        }
                //    }
                //    List<LatLng> listOfPositions = new List<LatLng>();
                //    bool end = false;
                //    while (!end)
                //    {
                //        //Debug.Log("Is it going here?");
                //        var pos = net_manager.m_nodes.m_buffer[nodeId].m_position;
                //        var rwoX = pos.x + centerUTM.Easting;
                //        var rwoY = pos.z + centerUTM.Northing;
                //        LatLng rwoLL = convertor.convertUtmToLatLng(rwoX, rwoY, centerUTM.ZoneNumber, ZoneLetter);
                //        listOfPositions.Add(rwoLL);

                //        if (start_end_nodes.ContainsKey(nodeId))
                //            nodeId = start_end_nodes[nodeId];
                //        else
                //            end = true;
                //    }
                //    //Debug.Log("listOfPositions.Count: " + listOfPositions.Count.ToString());
                //    var roadLineWkt = createWkt(listOfPositions.ToArray());

                //    string rowTxt = string.Format("{0},{1},{2},{3}", cnt, road_name, roadLineWkt, field_info);
                //    txtLines.Add(rowTxt);
                //    //Debug.Log(debug_msg);
                //}

                //StreamWriter outputFile = new StreamWriter("Files/roads_cs.csv", false, new UTF8Encoding(true));
                //foreach (var lineTxt in txtLines)
                //{
                //    outputFile.WriteLine(lineTxt);
                //}
                //outputFile.Close();

                //panel.SetMessage("Jan's mod", msg, false);
            }
        }