2016-07-21 8 views
1

Ich habe eine Liste von lat langen Koordinaten jeweils mit entsprechenden Azimuten (Richtungen), wie zB:Karte erstellen Polygonen von Excel-Daten in R

Site | Cell  | Lat | Long | Azimuth (degrees) | Beamwidth 
    CE0001 | CE0001U09A1 | X | Y | 0    | 65 
    CE0001 | CE0001U09B1 | X | Y | 120   | 65 
    CE0001 | CE0001U09C1 | X | Y | 240   | 65 

Für jede einzelne Zelle, würde Ich mag einen dreieckigen Polygon erstellen, ist in der Richtung des Azimuts für die entsprechende Zelle mit einer Breite von 65 Grad und einem Radius von beispielsweise 2 km ausgerichtet. Ich möchte ähnliche Formen wie unten gezeigt erzeugen.

Kann mir jemand in die Richtung zeigen, wie ich anfangen könnte, dies zu kodieren, um jeden Eintrag in meiner Datei durchzulaufen und wie man eine einzelne Google Earth-Datei erzeugt, die für jedes ein Polygon enthält? Es gibt ungefähr 9000 Zellen, die ein Polygon benötigen, aber wenn ich das für eine kleine Probe arbeiten kann, wäre ich sehr glücklich.

Google Earth Azimuth Example

+0

Was Sie machen wirklich beeindruckende Sounds! Könnten Sie bitte erklären, wie das Endergebnis aussehen soll? –

+0

Sie suchen noch eine Lösung dafür? Und ich verstehe dich richtig, dass du als Ergebnis für jeden Punkt drei Polygone willst? –

+0

Hi @and, ich denke, ich habe herausgefunden, dass dies eine grundlegende Trigonometrie ist, es ist sehr grob, aber es funktioniert. Da ich eine Standortkoordinate, eine Strahlbreite, eine Entfernung zur Kante und eine Anzahl von Punkten habe, die ich berechnen möchte, ist die destPoint-Funktion im Geosphärenpaket wirklich nützlich. Es berechnet die Endpunkte entlang des Polygons und ich kann sie dann im Prospekt abbilden. Wenn Sie eine bessere Alternative haben, würde ich mich freuen, davon zu hören. – TheGoat

Antwort

1

Hier und alte Post ich zu einem Forum von einem Skript aus Sechseck Fliesen zu bauen. Einige der Anrufe auf den GIS-API, aber ich denke, Sie wahrscheinlich den benötigten VBA-Code extrahiert werden:

 .. VB script to create some hexagon tiles. 
     It creates tiles of a given radius (circle around a tile), not side length. If you want side length you will need to do the math and updte the code. 
     Here is the Comments from the .map file: 
     Creating a drawing of hexagon tiles: 
     R - radius 
     Radius of circumscribed circle around tile 
     a - Apothem: 
     Distance from centroid perpendicular to a side 
     a = R * cos(1/2 * 360/n) (n=6 for a hexagon 
     A set of hexagon tiles would be a series of six sided 
     "circles" centered on two point grids (1 & 2). Both grids 
     would have the spacing of: 
     in X --- 3R 
     in Y --- 2a 
     Grid 2 would be offset from grid 1 by: 
     in X ---- 3R/2 
     in Y ---- 2a/2 
     To test script delete all objects in A then 
     run the script. 
     This sample was only tested with a lat/long drawing. I'm not 
     sure of all the ramifications of using a projected drawing. 
     To use with your data set the start point (upper left) in the script and desired radius. 
     Set precision and run Normailize Topology when done to join 
     the tiles. 
     Code was based on the FreeStuff sample scripts ScriptRandomPoints 
     and ScriptSpatialOperations. 
     Please post any problems you find with this code. 
     Hmmm.. the attachments option is gone? :-? 
     Send me your address via email and send the .map file if you'd like. 
     Here's the code: 
      Sub Main 
      ' test lat/long drawing 
      ' ** ** delete all objects in A to test 
      set drawing = Application.ActiveDocument.ComponentSet("A") 
      set objects = drawing.ObjectSet 
      sides = 6 
      pi = 3.14159 
      R = 2.5 ' radius in degrees 
      interiorAngle = (360/6) * (pi/180) ' in radians 
      a = abs(R * cos(0.5 * interiorAngle)) ' apothem 
      ' pick/make a start point - upper left 
      Set startPoint = Application.NewPoint 
      startPoint.X = -25 
      startPoint.Y = 73.6602540378444 
      ' grid (4x3x2) 
      for i = 0 to 3 
      for j = 0 to 2 
      ' -- create point grid 1 
      Set point = Application.NewPoint 
      point.X = startPoint.X + (i * 3 * R) 
      point.Y = startPoint.Y - (j * 2 * a) 
      ' objects.Add Application.NewGeom(GeomPoint, point) ' centroid 
      Set pointSet = Application.NewPointSet 
      For k = 0 To sides -1 
      Set pt = Application.NewPoint 
      ' calculate angle 
      angle = (k*2*Pi/sides)' - (360/sides)/2 
      ' obtain point on circle 
      pt.X = point.X + R*Cos(angle) 
      pt.Y = point.Y + R*Sin(angle) 
      pointSet.Add(pt) 
      Next 
      objects.Add Application.NewGeom(GeomArea, pointSet) 
      ' -- create point grid 2 
      Set point = Application.NewPoint 
      point.X = startPoint.X + (i * 3 * R) + ((3 * R)/2) 
      point.Y = startPoint.Y - (j * 2 * a) - a 
      ' objects.Add Application.NewGeom(GeomPoint, point) ' centroid 
      Set pointSet = Application.NewPointSet 
      For k = 0 To sides -1 
      Set pt = Application.NewPoint 
      ' calculate angle 
      angle = (k*2*Pi/sides)' - (360/sides)/2 
      ' obtain point on circle 
      pt.X = point.X + R*Cos(angle) 
      pt.Y = point.Y + R*Sin(angle) 
      pointSet.Add(pt) 
      Next 
      objects.Add Application.NewGeom(GeomArea, pointSet) 
      next 
      next 
      msgbox "Done!" 
      End Sub 

Hier ist eine aufgeräumt Version, die ein Sechseck Fliese entwickelt gerade. Sie sollten es ändern können, um zu tun, was Sie wollen.

 Sub xx() 
      Dim startPoint As clsPoint 
      Dim Point As clsPoint 
      Dim pt As clsPoint 
      Dim pts As Collection 
      Dim s As String 

      ' lat/long (western hemisphere?) 

      Dim sides, i, j, k As Integer 
      Dim Pi, R, interiorAngle, A, Angle As Double 

      sides = 6 
      Pi = 3.14159 
      R = 0.25 ' radius in degrees 
      interiorAngle = (360/6) * (Pi/180) ' in radians 
      A = Abs(R * Cos(0.5 * interiorAngle)) ' apothem 

      ' pick/make a start point - upper left 
      Set startPoint = New clsPoint 
      startPoint.X = -121.5 
      startPoint.Y = 35.5 
      s = "Longitude" & vbTab & "Latitude" & vbCrLf 
      s = s & startPoint.X & vbTab & startPoint.Y & vbCrLf 

      Set Point = New clsPoint 
      Point.X = startPoint.X '+ (i * 3 * R) 
      Point.Y = startPoint.Y '- (j * 2 * A) 

      Set pts = New Collection 
      For k = 0 To sides - 1 
       Set pt = New clsPoint 
       ' calculate angle 
       Angle = (k * 2 * Pi/sides) ' - (360/sides)/2 
     '  Debug.Print Angle 
       ' obtain point on circle 
       pt.X = Point.X + R * Cos(Angle) 
       pt.Y = Point.Y + R * Sin(Angle) 
       pts.Add pt 
      Next 

      For Each pt In pts 
       s = s & pt.X & vbTab & pt.Y & vbCrLf 
      Next 
      Debug.Print s 
      Stop 
     End Sub 

clsPoint enthält nur:

Public X As Double 
Public Y As Double 
+0

Danke für die Antwort, hätten Sie ein Bild der Ausgabe, damit ich visualisieren kann, was es erzeugt? Es wird eine Weile dauern, bis ich das Skript entschlüsselt habe. Vielen Dank im Voraus. – TheGoat

+0

Die Ausgabe ist nur sechs Punkte und ein Schwerpunkt. Das obige Skript druckt nur die Punkte im unmittelbaren Fenster. – rheitzman

Verwandte Themen