0

my problem is the following. I am writing a Matlab script, in which I want to perform the following steps:

  • step1: Create a map (contour plot) on which seismic hazard (spectral displacement) as a function of region (Italy) is shown.
  • step2: Extract the coordinates (getcountourlines) and the corresponding hazard values.
  • step3: transform the extracted coordinates of the individual contour lines into SQL spatial data.

I successfully proceeded step 1 and 2, and now I am struggeling with step 3. Let's have a look at a simple but fictitious example:

contourline1 = [x1 y1 x2 y2 x3 y3 x1 y1];
contourline2 = [x4 y4 x5 y5 x6 y6 x4 y4];

with x1,...x6 and y1,...y6 as real numbers (coordinates). Hereby, contourline1 is the outline and contourline2 is the "hole" (or in different words: contourline2 is a real subset of contourline1). What is now my Goal?

GOAL: I would like that Matlab takes contourline1 and contourline2 and transforms it into SQL spatial data. Matlab's output should be a string, such that I simply can copy/paste it into SQL. The output string (SQL readable) should be of the following form:

POLYGON((x1 y1, x2 y2, x3 y3, x1 y1),(x4 y4, x5 y5, x6 y6, x4 y4))

In my script, I already combined "outline" and "hole":

outline_hole = [x1 y1 x2 y2 x3 y3 x1 y1 x4 y4 x5 y5 x6 y6 x4 y4];

That means that Matlab has to "complement" the vector above (outline_hole) with "(", ")" and ",". Does someone have an idea how to do that efficiently?

Thank you in advance for your help.

SpaceCowboy

Turi
  • 25
  • 7

1 Answers1

0

If I understand you right, you just want to compose a string?

c1 = 1:8;    % 1     2     3     4     5     6     7     8
c2 = 9:16;   % 9    10    11    12    13    14    15    16

output = ['POLYGON((' num2str(c1(1:2)) ', ' num2str(c1(3:4)) ', '  ...
                      num2str(c1(5:6)) ', ' num2str(c1(7:8)) '),(' ... 
                      num2str(c2(1:2)) ', ' num2str(c2(3:4)) ', '  ...
                      num2str(c2(5:6)) ', ' num2str(c2(7:8)) '))' ]

output = 

    'POLYGON((1  2, 3  4, 5  6, 7  8),(9  10, 11  12, 13  14, 15  16))'
Robert Seifert
  • 25,078
  • 11
  • 68
  • 113
  • Dear "thewaywewalk", that is exactly what I was looking for. In my case, the vector outline_hole has a much larger length, such that I have to apply a for-loop in order to set all the necessary commas. Thank you for your very useful help! – Turi Dec 09 '13 at 07:52
  • You're welcome. Instead of the loop you can also consider storing every single coordinate as a string in a cell array and also create an cell array of `' ,'` and `' '`. Finally you [interweave these two:](http://stackoverflow.com/questions/19842696/is-there-a-function-to-zip-two-cell-arrays-together/19842820#19842820) – Robert Seifert Dec 09 '13 at 08:14