-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpolyObj.m
64 lines (58 loc) · 2.29 KB
/
polyObj.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
%
% Class for a polygon.
%
% Copyright 2016 Elliot Sefton-Nash
classdef polyObj
properties(GetAccess = 'public', SetAccess = 'public')
x; % Vector of x coordinates of vertices.
y; % Vector of y coordinates of vertices.
lat; % Vector of latitude coordinates of vertices.
lon; % Vector of longitude coordinates of vertices.
nvertices; % Number of vertices
xc; % x - Coordinate of centroid
yc; % y - Coordinate of centroid
latc; % latitude of centroid
lonc; % longitude of centroid
areaPoly; % Area of polygon
end
% Methods, including the constructor are defined in this block.
methods
function obj = polyObj(shp)
% If this is not empty, then shp contains a structure
% containing a single polygon as returned by shaperead.
if ~isempty(shp)
if strcmpi(shp.Geometry,'polygon')
obj.nvertices = numel(shp.X);
% Last vertex is NaN, polygon must be at least a triangle.
if obj.nvertices < 4
obj = [];
return
end
obj.x = shp.X;
obj.y = shp.Y;
%obj.xc = shp.Xcenter;
%obj.yc = shp.Ycenter;
% Typically the last element of polygon
% vertices is NaN, ignore those.
obj.areaPoly = polyarea(shp.X(1:end-1), shp.Y(1:end-1));
else
obj = [];
end
else
obj = [];
end
end
% Function to calculate lat-lon coordinates for the vertices
% assuming that the xy coordinates that describe the polygon are
% equal-area cylindrical coordinates.
%
% Inputs:
% lat1 - latitude of first standard parallel
% lonO - longitude of origin
% r - radius of spherical body in map-units.
function obj = getLatLonFromEqaXY(obj ,fe,fn,r,lat1,lonO)
[obj.lonc, obj.latc] = eqa2latlon(obj.xc,obj.yc,fe,fn,r,lat1,lonO);
[obj.lon, obj.lat] = eqa2latlon(obj.x,obj.y,fe,fn,r,lat1,lonO);
end
end
end