Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Geonear converting latitudes and lomgitudes

    Hi Statalist
    I have a dataset with grid points (Latitude and Longitude). I want to match these with a GIS file that contains district coordinates (Latitude and Longitude) that are polygon centroids.
    As i understand this can be addressed by geoinpoly and geonear
    I am trying to use geonear to find the nearest neighbour for every grid point. My issue is that my latitudes and longitudes do not fall in the 90 to -90 and 180 to -180 range as is required.
    I will appreciate any suggestions on how to solve this issue as i am quite new to geonear

    A sample of my data is
    The grid file
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(LAT LON idd)
    7.5 94.5   1
    7.5 94.5   2
    7.5 94.5   3
    7.5 94.5   4
    7.5 94.5   5
    7.5 94.5   6
    7.5 94.5   7
    7.5 94.5   8
    7.5 94.5   9
    7.5 94.5  10
    7.5 94.5  11
    7.5 94.5  12
    7.5 94.5  13
    7.5 94.5  14
    7.5 94.5  15
    7.5 94.5  16
    7.5 94.5  17
    7.5 94.5  18
    7.5 94.5  19
    7.5 94.5  20
    7.5 94.5  21
    7.5 94.5  22
    7.5 94.5  23
    7.5 94.5  24
    7.5 94.5  25
    7.5 94.5  26
    7.5 94.5  27
    7.5 94.5  28
    7.5 94.5  29
    7.5 94.5  30
    7.5 94.5  31
    7.5 94.5  32
    7.5 94.5  33
    7.5 94.5  34
    7.5 94.5  35
    7.5 94.5  36
    7.5 94.5  37
    7.5 94.5  38
    7.5 94.5  39
    7.5 94.5  40
    7.5 94.5  41
    7.5 94.5  42
    7.5 94.5  43
    7.5 94.5  44
    7.5 94.5  45
    7.5 94.5  46
    7.5 94.5  47
    7.5 94.5  48
    7.5 94.5  49
    7.5 94.5  50
    7.5 94.5  51
    7.5 94.5  52
    7.5 94.5  53
    7.5 94.5  54
    7.5 94.5  55
    7.5 94.5  56
    7.5 94.5  57
    7.5 94.5  58
    7.5 94.5  59
    7.5 94.5  60
    7.5 94.5  61
    7.5 94.5  62
    7.5 94.5  63
    7.5 94.5  64
    7.5 94.5  65
    7.5 94.5  66
    7.5 94.5  67
    7.5 94.5  68
    7.5 94.5  69
    7.5 94.5  70
    7.5 94.5  71
    7.5 94.5  72
    7.5 94.5  73
    7.5 94.5  74
    7.5 94.5  75
    7.5 94.5  76
    7.5 94.5  77
    7.5 94.5  78
    7.5 94.5  79
    7.5 94.5  80
    7.5 94.5  81
    7.5 94.5  82
    7.5 94.5  83
    7.5 94.5  84
    7.5 94.5  85
    7.5 94.5  86
    7.5 94.5  87
    7.5 94.5  88
    7.5 94.5  89
    7.5 94.5  90
    7.5 94.5  91
    7.5 94.5  92
    7.5 94.5  93
    7.5 94.5  94
    7.5 94.5  95
    7.5 94.5  96
    7.5 94.5  97
    7.5 94.5  98
    7.5 94.5  99
    7.5 94.5 100
    end
    The GIS file
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(x_c y_c) int id
     74.29764  36.37415   1
    75.636375  35.38476   2
     76.66502  35.36059   3
     73.69609 35.758064   4
     79.12216 35.030567   5
     74.99791   35.2789   6
    74.316414 35.416504   7
     77.91751 33.934277   8
      74.0153 34.667522   9
     74.99393  34.76488  10
     74.16609  34.38015  11
     74.72942  34.44623  12
     76.62077 33.812244  13
     75.10275 34.245647  14
     75.33213   33.8039  15
      76.0409 33.457706  16
     74.78827 33.945435  17
     73.84618   33.8917  18
     74.35662 33.758724  19
     75.02168  33.83983  20
     73.93203  33.27063  21
        74.33 33.163204  22
     75.45106 33.038002  23
     74.82907 33.251595  24
     77.60422 32.478596  25
     76.41702 32.649895  26
      79.3519 32.843716  27
     74.94873 32.716347  28
      75.6431  32.54342  29
     75.46049 32.002804  30
     77.44077 31.886263  31
     78.61996 32.089985  32
     78.39954  31.59011  33
     74.92443 31.521526  34
    75.987404  31.52455  35
     77.06017 31.594364  36
      77.6962 31.175465  37
     75.43105  31.33191  38
     76.73202  31.32611  39
    75.778595  31.12359  40
     79.11017  31.24749  41
     76.61606 30.919376  42
    75.883514 31.210377  43
     78.50808  30.93282  44
     77.00807 31.003105  45
     79.45107  30.52177  46
     77.47031 30.636984  47
     75.97901 30.748606  48
     77.96883 30.433144  49
     80.14169  30.73001  50
     78.55444 30.424166  51
     80.25822 29.965845  52
     76.83641  30.67591  53
     76.48351 30.317503  54
     75.86491 30.217686  55
     79.59782 29.802814  56
     78.75726  29.87205  57
     74.09864  29.30311  58
     78.40327  29.33682  59
     77.62046  29.40121  60
     79.46494 29.179787  61
     95.84026  28.75149  62
      94.5524 28.578394  63
     78.59637 28.727774  64
     79.12862 28.793043  65
     73.17213 28.165806  66
    74.705315  28.21952  67
      95.0773  28.35754  68
     79.44805 28.460186  69
     79.97113  28.55045  70
     77.18721 28.575996  71
     93.88018 28.298384  72
     80.64906 28.135067  73
     79.86494 27.982725  74
     96.56201  28.06059  75
     75.65158 28.017847  76
     78.96577 28.082516  77
     81.57264  27.72303  78
     93.56244 27.733534  79
     76.68678 27.546114  80
     88.52406  27.74051  81
     78.18516 27.822206  82
    75.437485  27.55957  83
     70.99249   27.0859  84
     78.82445 27.603064  85
     92.55012 27.395876  86
     80.86832 27.537664  87
     77.76353  27.53769  88
      91.9893  27.64019  89
     82.16897 27.286453  90
     96.41525  27.48775  91
     95.07378  27.47257  92
    75.973724 26.882647  93
      80.1973  27.34674  94
     79.62188 27.230976  95
      93.1208  27.30229  96
     74.31233 27.017635  97
     88.16219 27.329447  98
     72.94178 26.709484  99
     88.37589  27.28216 100
    end

  • #2
    Well both data examples are within the correct range (assuming that x_c are longitudes and y_c are latitudes). The points from the second dataset are identical so I don't know what's up with that. If you save the second dataset under "district_coor.dta", then the following command will find the nearest neighbor for each point in the first dataset:

    Code:
    geonear idd LAT LON using "district_coor.dta", neighbor(id y_c x_c)

    Comment

    Working...
    X