Used to be that RAW, the sniper wasn't getting the sneak attack. Why? No good reason other than that "a legalistic reading of the rules said so." There are no end of huge threads on paizo.com going over in tortuous detail how vision and stealth and all that work in PF core, especially here and here, and the summary was "slavishly following the rules means things that make no sense." You never get sneak attack from stealth because "you can't stealth while attacking" and "it doesn't say you get sneak attack just because someone can't see you, as hidden isn't an official condition (tm)."
I would previously invoke GM privilege to implement RAI - as in Pathfinder they say clearly "the GM is the law over and above the written rules" - and make it so they get their sneak attack. Because it makes sense from a game world logic/sim point of view and you can rule that's more important than the RAW point of view. IMO the clear intent was to sneak-attack someone from Stealth. You know, "sneak," "attack," things that happen in the real world and every previous edition of D&D.
Can I Attack From Stealth?
Now, however, the Stealth rules have been errata'ed to specifically say "you can attack from stealth" which means that yes, you get the sneak attack. See the updated version on the PRD which says:
Breaking Stealth: When you start your turn using Stealth, you can leave cover or concealment and remain unobserved as long as you succeed at a Stealth check and end your turn in cover or concealment. Your Stealth immediately ends after you make an attack roll, whether or not the attack is successful (except when sniping as noted below).
Sniping: If you've already successfully used Stealth at least 10 feet from your target, you can make one ranged attack and then immediately use Stealth again. You take a –20 penalty on your Stealth check to maintain your obscured location.
So the RAW has been updated to match the RAI for whatever that's worth (apparently it's really meaningful to some, though all my rogues have been happily sneak attacking from Stealth since the year 2000...).
Does A Stealthed Attack Enable Sneak Attack?
Yes, if you're stealthed, your attacks are sneak attacks.
Jason Buhlman states the intent clearly on the Paizo forums:
For simplicities sake, it should be assumed that those making Perception checks get to do so at the most favorable point during the movement of a character using Stealth, to avoid making checks every time the condition changes. Technically, I think you would get a check whenever the conditions change, but that might make things overly complicated during play.
Creatures are denied their Dexterity bonus to AC "if they cannot react to a blow" (CR pg 179 under AC). It was our intent that if you are unaware of a threat, you cannot react to a blow. I think we probably should have spelled this out a wee bit clearer, but space in the Stealth description was extraordinarily tight and ever word was at a premium. That said, I think these changes clear up the situation immensely (compared to where they were.. which was nebulous at best).
They didn't bother changing the RAW because most people use common sense and play it that way. Stealthed = sneak, etc.
RAW + Pathfinder = Sad Panda
This is why, whether you like this or not, a pure RAW approach to Pathfinder is always going to be frustrating; the devs explicitly don't bother to clean up RAW when RAI and/or common sense is clear. It's not a priority of theirs and I for one am pretty happy about that - they spend their intellectual capital making new interesting fun content instead of crafting rules and just retreading the same content year after year like WotC did with 3.5 (Return to the Return to the 1e Module, anyone?).
Tremorsense reveals the location of invisible attackers; it doesn't offer protection from sneak attack damage
The extraordinary ability tremorsense says that it
can automatically pinpoint the location of anything that is in contact with the ground. Aquatic creatures with tremorsense can also sense the location of creatures moving through water. The ability’s range is specified in the creature’s descriptive text.
Pinpointing a target's location doesn't negate the concealment granted by an effect like the spell invisibility. A creature with tremorsense that pinpoints an invisible creature's location can make attacks against an invisible creature (albeit with a 50% miss chance) without first locating the invisible creature using other methods (like flailing around like an idiot). Being able to make such attack semi-accurately doesn't make the creature with tremorsense immune to sneak attacks. The creature with tremorsense still can't see what the invisible creature is doing.
Example 1
Abe, lacking tremorsense, is unaware of Bob because Bob is invisible through an invisibility spell.
- Surprise Round: Bob stabs flat-footed Abe. Bob's invisibility spell ends.
- Round 1: Initiative checks are made. Bob acts then Abe acts. Bob takes the full attack action and makes several attacks versus flat-footed Abe. Abe dies.
Example 2
Abe, having gained tremorsense 30 ft., is aware of Bob despite Bob's invisibility spell.
- Round 1: Initiative checks are made. Bob acts then Abe acts. Bob takes a move action to get into position then takes a standard action to make a standard attack against flat-footed Abe. Bob's invisibility spell ends. Abe take a 5-ft. step away from Bob and takes a standard action to cast the spell finger of death on Bob. Bob makes a Fortitude saving throw, fails that saving throw, is dealt 200 points of damage, and dies.
Example 3
While affected by an invisibility spell Bob teleports adjacent to Abe. Abe, possessing tremorsense 30 ft., is aware of Bob's presence.
- Round 1: Initiative checks are made. Bob acts then Abe acts. Bob takes the full-attack action to make several attacks against flat-footed Abe. After the first attack, Bob's invisibility spell ends. Abe, who has yet to act, remains flat-footed. Bob continues his full attack action, still his dealing sneak attack damage to flat-footed Abe. Abe dies.
Example 4
While affected by an invisibility spell Bob teleports adjacent to Abe. Abe, possessing tremorsense 30 ft., is aware of Bob's presence.
- Round 1: Initiative checks are made. Abe acts then Bob acts. Abe can't target Bob with the spell finger of death because, while Abe knows Bob's location, Abe can't actually see Bob. Abe, instead, uses flame strike to affect an area so as to catch Bob in the spell's effect. Bob makes a Reflex saving throw, succeeds on the saving throw, and takes no damage because of his extraordinary ability evasion. Bob takes the full-attack action to make several attacks against Abe. The first attack (which must be at Bob's highest base attack bonus against Abe) deals sneak attack damage: although Abe is no longer flat-footed Bob still benefits from the spell invisibility. After that first attack, however, the invisibility spell ends, and Bob's remaining attacks don't deal sneak attack damage.
To be clear, I've omitted a host of things from these examples to make them concisely address the question, chief among them the Perception checks that Abe gets against Bob to help him survive the attack from the invisible ninja.
Best Answer
There are a lot of different ways someone can be denied their DEX bonus to AC, so "it depends." So the first thing you need to note is that
d20PFSRD:
You do NOT need an opponent to be flat-footed in order to sneak attack them. Now, being flat-footed does deprive you of DEX bonus to AC, so it also triggers sneak attack, but
a) flat-footed does more than just that, like prevent you from making AoOs, so read the condition and
b) there's a lot more ways of being deprived of your DEX bonus short of being flat-footed (blinded, stunned, the opponent being hidden, about a dozen feats, etc).
Confusing flat-footed with denied DEX to AC will lead you astray in many cases. When a rule says one that's what it means, and while flat-footed also means deprived of DEX to AC the converse is NOT true.
Surprise Rounds
During a surprise round, an opponent is flat-footed, and does not lose the flat-footed condition until their first action. So they may be sneak-attacked with impunity by multiple attackers, or multiple times by you if you can somehow do that in the one action a surprise round gives you.
Invisibility
Unless you have improved invisibility, with normal invisibility you become visible as soon as you attack, so the target is only denied their DEX bonus to AC for the first attack. They are NOT flat-footed, so can take attacks of opportunity if they know where you are. If they know you're there from a DC20 Perception check, I'd say it's a little ambiguous RAW-wise whether they'd get an AoO from, for example, you attacking from invis with a combat maneuver that provokes (grappling them without Improved Grapple for example) - most GMs would rule not, but be advised that invis isn't perfect and has a lot of caveats in its description.
Other
There's a lot of ways to lose DEX to AC and they're all different, and whether they persist for one attack or one round or forever is all based on the specific power.
Also see