BookmarkSubscribe
Choose Language Hide Translation Bar
Occasional Contributor

## exporting x&y values (coordinates) from graph builder once jmp automatically finds centroid points for a polygon

How can I export x&y coordinates for the centroid points jmp automatically finds within my polygons (n=2455) on a graph builder map? I would like to make lat/long columns for these points in order to make contour and heat maps, but all I have currently are the many vertices coordinates for the mapshape polygons. These are municipalities in Mexico, so there is no determined point location (city) for the ad on to find (if it could), but the centroid points jmp finds is perfect for me. I don't know how to write script.

1 ACCEPTED SOLUTION

Accepted Solutions
Community Trekker

## Re: exporting x&y values (coordinates) from graph builder once jmp automatically finds centroid points for a polygon

Fever,

Here is a quick script I wrote to find the centroids based on the XY shape file.  Please try and let me know how it works for you.

``````dt = Current Data Table();
shapeList = Associative Array( Column( dt, "Shape ID" ) << get values ) << get keys;
dtCentroids = New Table("Centroids", New Column( "Shape ID", numeric, continuous ),
New Column( "X", numeric continuous ),
New Column( "Y", numeric, continuous )
);
For( i = 1, i <= N Items( shapeList ), i++,
targetRows = dt << get rows where( Column( dt, "Shape ID" )[Row()] == shapeList[i] );
centroid = Polygon Centroid( Column( dt, "X" )[targetRows], Column( dt, "Y" )[targetRows] );
dtCentroids << add rows( 1, "at end" );
Column( dtCentroids, "Shape ID" )[i] = i;
Column( dtCentroids, "X" )[i] = centroid[1];
Column( dtCentroids, "Y" )[i] = centroid[2];
);``````
7 REPLIES 7
Occasional Contributor

## Re: exporting x&y values (coordinates) from graph builder once jmp automatically finds centroid points for a polygon

Using the crosshair tool manually on all the points and recording these isn't practical for me. Thanks

Community Trekker

## Re: exporting x&y values (coordinates) from graph builder once jmp automatically finds centroid points for a polygon

Fever,

What I did was take the mean X and Y values (using table>summary) for each of my shapes in the XY polygon file.  This is not really a centriod, but it worked well enough for my purposes.

John

@fever wrote:

Using the crosshair tool manually on all the points and recording these isn't practical for me. Thanks

Occasional Contributor

## Re: exporting x

Thanks, yes that works w most of the shapes. Good enough from a distance. Thought maybe there were a simple way to access the automatically generated centroid data
Community Trekker

## Re: exporting x&y values (coordinates) from graph builder once jmp automatically finds centroid points for a polygon

Fever,

Here is a quick script I wrote to find the centroids based on the XY shape file.  Please try and let me know how it works for you.

``````dt = Current Data Table();
shapeList = Associative Array( Column( dt, "Shape ID" ) << get values ) << get keys;
dtCentroids = New Table("Centroids", New Column( "Shape ID", numeric, continuous ),
New Column( "X", numeric continuous ),
New Column( "Y", numeric, continuous )
);
For( i = 1, i <= N Items( shapeList ), i++,
targetRows = dt << get rows where( Column( dt, "Shape ID" )[Row()] == shapeList[i] );
centroid = Polygon Centroid( Column( dt, "X" )[targetRows], Column( dt, "Y" )[targetRows] );
dtCentroids << add rows( 1, "at end" );
Column( dtCentroids, "Shape ID" )[i] = i;
Column( dtCentroids, "X" )[i] = centroid[1];
Column( dtCentroids, "Y" )[i] = centroid[2];
);``````
Occasional Contributor

## Re: exporting x&y values (coordinates) from graph builder once jmp automatically finds centroid points for a polygon

That worked after chopping up the file 5 ways (was 87k rows). Program kept freezing...But it looks good. Thanks!

Highlighted
Community Trekker

## Re: exporting x&y values (coordinates) from graph builder once jmp automatically finds centroid points for a polygon

Glad to hear it worked.  Happy JMPing!

Staff

## Re: exporting x&y values (coordinates) from graph builder once jmp automatically finds centroid points for a polygon

FWIW, here is an alternative that uses plotted data directly:

``````NamesDefaultToHere(1);

// Table
dt = New Table( "Some States",
New Column(
"State",
Character,
Nominal,
Set Values(
"Connecticut", "Delaware", "Florida", "Georgia", "Hawaii"}
)
)
);

// Map
gb = dt << Graph Builder(
Show Control Panel( 0 ),
Variables( Shape( :State ) ),
Elements( Points( Legend( 5 ) ) )
);

// Get x and y values from marker seg
gbRep = Report(gb);
frame = gbRep[FrameBox(1)];
mySeg = (frame << Find Seg( Marker Seg( 1 ) ));
xVals = mySeg << Get X Values;
yVals = mySeg << Get Y Values;
dt2 = asTable(xVals||yVals, << columnNames({"X", "Y"}));
dt2 << setName("Map Shape Centroids");``````