Changeset 21651


Ignore:
Timestamp:
03/30/17 10:27:08 (8 years ago)
Author:
Mathieu Morlighem
Message:

CHG: pass shp as first argument + added check on extension

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/shp/shp2exp.m

    r21349 r21651  
    1 function Shp2Exp(expfilename,shapefilename)
     1function shp2exp(shpfilename,expfilename)
    22%SHP2EXP- transform shape file to Argus .exp file
    33%
    44%   Usage:
    5 %      Shp2Exp(expfilename,shapefilename);
     5%      shp2exp(shpfilename,expfilename);
    66%
    77%   Example:
    8 %      Shp2Exp('Domain.exp','Domain.shp');
     8%      shp2exp('Domain.shp','Domain.exp');
    99%
    1010%   See also EXPMASTER, EXPDOC
    1111
    12         if ~exist(shapefilename,'file'),
    13                 error(['Shapefile ' shapefilename ' does not exist']);
     12%check file extensions
     13[pathstr,name,ext] = fileparts(shpfilename);
     14if ~strcmp(ext,'.shp'),
     15        error(['Shapefile ' shpfilename ' does not have an extension .shp']);
     16end
     17
     18[pathstr,name,ext] = fileparts(expfilename);
     19if ~strcmp(ext,'.exp'),
     20        error(['Exp file ' expfilename ' does not have an extension .exp']);
     21end
     22
     23if ~exist(shpfilename,'file'),
     24        error(['Shapefile ' shpfilename ' does not exist']);
     25end
     26shp=shaperead(shpfilename);
     27
     28expstruct=struct([]);
     29for i=1:length(shp),
     30        if strcmpi(shp(i).Geometry,'Polygon'),
     31                x=shp(i).X; y=shp(i).Y;
     32                ids=find(isnan(x));
     33                x(ids)=[]; y(ids)=[];
     34                expstruct(end+1).x=x;
     35                expstruct(end).y=y;
     36                expstruct(end).nods=length(x);
     37                expstruct(end).density=1;
     38                expstruct(end).closed=1;
     39                expstruct(end).name=num2str(shp(i).id);
     40        elseif strcmpi(shp(i).Geometry,'Point'),
     41                x=shp(i).X; y=shp(i).Y;
     42                expstruct(end+1).x=x;
     43                expstruct(end).y=y;
     44                expstruct(end).nods=length(x);
     45                expstruct(end).density=1;
     46                expstruct(end).closed=0;
     47                %exp(end).name=num2str(shp(i).id);
     48        elseif strcmpi(shp(i).Geometry,'Line'),
     49                x=shp(i).X; y=shp(i).Y;
     50                expstruct(end+1).x=x;
     51                expstruct(end).y=y;
     52                expstruct(end).nods=length(x);
     53                expstruct(end).density=1;
     54                expstruct(end).closed=0;
    1455        end
    15         shp=shaperead(shapefilename);
     56end
    1657
    17         expstruct=struct([]);
    18         for i=1:length(shp),
    19                 if strcmpi(shp(i).Geometry,'Polygon'),
    20                         x=shp(i).X; y=shp(i).Y;
    21                         ids=find(isnan(x));
    22                         x(ids)=[]; y(ids)=[];
    23                         expstruct(end+1).x=x;
    24                         expstruct(end).y=y;
    25                         expstruct(end).nods=length(x);
    26                         expstruct(end).density=1;
    27                         expstruct(end).closed=1;
    28                         expstruct(end).name=num2str(shp(i).id);
    29                 elseif strcmpi(shp(i).Geometry,'Point'),
    30                         x=shp(i).X; y=shp(i).Y;
    31                         expstruct(end+1).x=x;
    32                         expstruct(end).y=y;
    33                         expstruct(end).nods=length(x);
    34                         expstruct(end).density=1;
    35                         expstruct(end).closed=0;
    36                         %exp(end).name=num2str(shp(i).id);
    37                 elseif strcmpi(shp(i).Geometry,'Line'),
    38                         x=shp(i).X; y=shp(i).Y;
    39                         expstruct(end+1).x=x;
    40                         expstruct(end).y=y;
    41                         expstruct(end).nods=length(x);
    42                         expstruct(end).density=1;
    43                         expstruct(end).closed=0;
    44                 end
    45         end
    46 
    47         expwrite(expstruct,expfilename);
     58expwrite(expstruct,expfilename);
Note: See TracChangeset for help on using the changeset viewer.