## Copyright (C) 2014-2022 Philip Nienhuis ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program. If not, see . ## -*- texinfo -*- ## @deftypefn {Function File} [ @var{infs} ] = shapeinfo (@var{fname}) ## Returns a struct with info on shapefile @var{fname}. ## ## Input: ## @table @code ## @item @var{fname} ## (character string). Does not need to have a .shp suffix. ## @end table ## ## Output: a struct with fields: ## ## @table @code ## @item Filename ## Contains the filename of the shapefile. ## ## @item ShapeType ## The type of shapefile. ## ## @item ShapeTypeName ## The name of the shape type. ## ## @item BoundingBox ## The minimum and maximum X and Y coordinates of all items in the shapefile in ## a 2 X 2 array, upper rox min and min Y, lower row max X and max Y. ## ## @item NumFeatures ## The number of features (items, records) in the shapefile. ## ## @item Attributes ## A structure with fields Name and Type (containng the names and types of all ## attributes in the shapefile). Type can be Numeric, Character or Data. ## @end table ## ## @seealso{geoshow, mapshow, shapedraw, shaperead, shapewrite} ## @end deftypefn ## Author: Philip Nienhuis char"); until (ftell (fidp) > flngt - 3); ## i.e., within last ## file byte printf (" \n"); ## Wipe "Counting.." else ## shx file found; no counting required fseek (fidx, 24, "bof"); fxlng = fread (fidx, 1, "int32", 72, "ieee-be"); recn = (fxlng - 50) / 4; fclose (fidx); endif fclose (fidp); finfo = dir (fname); ## Return info infs.NumFeatures = recn; infs.FileSize = finfo.bytes; infs.LastModified = datestr (finfo.datenum, 0); ## ====================== 3. .dbf ====================== ## Check if dbfread is available if (isempty (which ("dbfread"))) printf ("shaperead: dbfread function not found. No attributes will be added.\n"); printf (" (io package installed and loaded?)\n"); else ## Try to read the .dbf file try [~, B] = dbfread ([bname ".dbf"], 0); infs.Attributes.Name = {B.data.fldnam}; types = {B.data.fldtyp}; types = strrep (types, "N", "Numeric"); types = strrep (types, "C", "Character"); types = strrep (types, "D", "Date"); types = strrep (types, "F", "Floating"); ## FIXME dbase also has type "Logical" infs.Attributes.Type = types; catch printf ("shaperead: file %s couldn't be opened;\n", [ bname ".dbf" ]); printf (" no attributes appended\n"); end_try_catch endif endfunction